Answer the question
In order to leave comments, you need to log in
How to optimize database queries in ZF?
There is a task to reduce reversal to a database. The project was implemented on ZF 1 with MySQL database.
At this stage, the records array is updated cyclically, which is not very correct.
the array looks like:
Array
(
[0] => Array
(
[uid] => bmw2
[query_id] => 74
)
[1] => Array
(
[uid] => bmw11
[query_id] => 6
)
...
)
foreach($result as $data)
$this->db->update('table',$data,'query_id = '.$data['query_id']);
Answer the question
In order to leave comments, you need to log in
Here the question actually arises of how and what needs to be updated.
You can set the same field for several records if you set WHERE containing several id lines. for example
WHERE `id` IN(1,2,8)
, if you need to set different values for different rows. I can’t say with certainty where, but I saw a system that collected all requests for updating and deleting rows in one request (by concatenation) and, in fact, this can also be done.
Or use a construct like
UPDATE `tbl` SET `field` = CASE
WHEN id = 1 THEN 123;
WHEN id = 2 THEN 456;
…
END
WHERE `id` IN (1,2,8)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question