IN and Zend\Db\Sql's where()
This is a short note to myself. Zend\Db\Sql objects allow you to do this:
1 2 |
$id = 2; $select->where(array('id' => $id)); |
which generates the (My)SQL:
1 |
WHERE `id` = '2' |
If you want the SQL generated to use the IN operator, then just pass in an array:
1 2 |
$idList = array(1, 3, 4); $select->where(array('id' => $idList)); |
which generates:
1 |
WHERE `id` IN ('1', '3', '4') |
This obviously also works for ZendDbSql‘s update() as well as select().