N
N
NetyNicka2015-02-03 15:18:39
MySQL
NetyNicka, 2015-02-03 15:18:39

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
        )
...
)

updated by cycle
foreach($result as $data)
$this->db->update('table',$data,'query_id = '.$data['query_id']);

The question is, is there an adequate way to replace the loop with 1 request?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Galkin, 2015-02-03
@NetyNicka

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)

But honestly, I don’t know how to implement this on zf1, read the documentation.

F
FanatPHP, 2015-02-03
@FanatPHP

The challenge is to reduce circulation

why?
why?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question