Pragmatism in the real world

IN and Zend\Db\Sql's where()

This is a short note to myself. Zend\Db\Sql objects allow you to do this:

$id = 2;
$select->where(array('id' => $id));

which generates the (My)SQL:

WHERE `id` = '2'

If you want the SQL generated to use the IN operator, then just pass in an array:

$idList = array(1, 3, 4);
$select->where(array('id' => $idList));

which generates:

WHERE `id` IN ('1', '3', '4')

This obviously also works for ZendDbSql‘s update() as well as select().