MySQL IN关键字和Zend Framework 2用于更新查询


MySQL IN keyword and Zend Framework 2 for update query

我试图在MySQL中使用IN关键字来跨多行更新。sessionsId是一个由整数id组成的array()。我尝试将它们内爆,但由于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));