I am trying to use the IN
keyword in MySQL to update across multiple rows. sessionsId is an array()
of integer ids. I tried imploding them, but it fails with a syntax error because of what Zend adds to the query. Other posts on Stack Overflow use a subquery, but here the IDs aren't coming from another query. How could I accomplish the update using an IN query?
$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);
You don't need implode:
$update->where(array('sessionsIds' => $sessionIDs));
You can do like this
$data = array("subscribed" => intval($subscribed));
$predicate = new \Zend\Db\Sql\Where();
$this->tableGateway->update($data, $predicate->in('sessionsIds',$sessionIDs)->AND->equalTo("participantId", $participantId));