How can I do update in doctrine, with array, so I don't do for loop for each time (I just want to do 1 call to database)
$myarray = [1, 2, 3];
$sql = "UPDATE `mytable` SET is_processing = :is_processing, end_time=NOW() WHERE id = :id";
$result = $this->connection->executeUpdate(
$sql,
array(
'is_processing' => false,
'id' => $myarray // This is unknown number amount of array
)
);
What I'm trying to achieve is: it should update the table with field is_processing = false, endTime become current time, where id = whatever the array point to
Use IN
clause in your query.
UPDATE `mytable` SET is_processing = :is_processing, end_time=NOW() WHERE id IN(:ids)
then
$result = $this->connection->executeUpdate(
$sql,
array(
'is_processing' => false,
'ids' => [3, 25]
),
array(
'ids' => \Doctrine\DBAL\Connection::PARAM_INT_ARRAY
)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With