MySQL 用于更新查询的 IN 关键字和 Zend Framework 2
MySQL IN keyword and Zend Framework 2 for update query
我正在尝试使用 MySQL 中的 IN
关键字来更新多行。 sessionsId 是一个 array()
的整数 ID。我尝试对它们进行内爆,但由于 Zend 添加到查询中的内容,它失败并出现语法错误。 Stack Overflow 上的其他帖子使用子查询,但此处的 ID 并非来自其他查询。如何使用 IN 查询完成更新?
$in = implode($sessionIDs,',');
$update = new Update();
$update->table("participantsToSessions");
$update->set(array("subscribed" => intval($subscribed)));
$update->where(array("participantId" => $participantId));
$update->where(array("sessionsIds IN (?)"=> $in));
//$str = $update->getSqlString();
$this->tableGateway->updateWith($update);
你不需要内爆:
$update->where(array('sessionsIds' => $sessionIDs));
你可以这样做
$data = array("subscribed" => intval($subscribed));
$predicate = new \Zend\Db\Sql\Where();
$this->tableGateway->update($data, $predicate->in('sessionsIds',$sessionIDs)->AND->equalTo("participantId", $participantId));
我正在尝试使用 MySQL 中的 IN
关键字来更新多行。 sessionsId 是一个 array()
的整数 ID。我尝试对它们进行内爆,但由于 Zend 添加到查询中的内容,它失败并出现语法错误。 Stack Overflow 上的其他帖子使用子查询,但此处的 ID 并非来自其他查询。如何使用 IN 查询完成更新?
$in = implode($sessionIDs,',');
$update = new Update();
$update->table("participantsToSessions");
$update->set(array("subscribed" => intval($subscribed)));
$update->where(array("participantId" => $participantId));
$update->where(array("sessionsIds IN (?)"=> $in));
//$str = $update->getSqlString();
$this->tableGateway->updateWith($update);
你不需要内爆:
$update->where(array('sessionsIds' => $sessionIDs));
你可以这样做
$data = array("subscribed" => intval($subscribed));
$predicate = new \Zend\Db\Sql\Where();
$this->tableGateway->update($data, $predicate->in('sessionsIds',$sessionIDs)->AND->equalTo("participantId", $participantId));