我怎么能用数组更新doctrine,所以我不做每次循环(我只想做1次调用数据库)
$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
)
);
我想要实现的是:
它应该使用字段is_processing = false更新表,endTime变为当前时间,其中id =数组指向的任何内容
解决方法:
在查询中使用IN子句.
UPDATE `mytable` SET is_processing = :is_processing, end_time=NOW() WHERE id IN(:ids)
然后
$result = $this->connection->executeUpdate(
$sql,
array(
'is_processing' => false,
'ids' => [3, 25]
),
array(
'ids' => \Doctrine\DBAL\Connection::PARAM_INT_ARRAY
)
);
标签:php,doctrine,symfony,doctrine-orm
来源: https://codeday.me/bug/20190611/1220029.html