What are the best workarounds for using a SQL IN clause with prepared statement, eg. PDO?
In a system I'm working on that uses Propel for handling the database, I'm preparing a raw query that needs to accept a varying WHERE IN condition.
googled somewhere,i found:
This is the PDO Workaround.
$ids = array(1, 2, 3, 4, 5);
$inQuery = implode(',', array_fill(0, count($ids), '?'));
$c = Propel::getConnection();
$q = $c->prepare("SELECT foo FROM bar WHERE id IN( {$inQuery} )");
// bindValue starts at 1 (not 0)
foreach ($ids as $key => $val)
{
$q->bindValue(($key+1), $val);
}
$q->execute();
Date: 2012-01-16 08:41:06 and last modified: 2012-01-16 08:42:16
Recent entries:
- Emacs rainbow mode
- Squirm a url rewriter for squid
- How to use rsync for transferring files over ssh
- Vide: GRE tunnel
- Video: how to install freebsd
- Video: Install zend framework
- Video: Install Window7 from network
- Install Window7 from a PXE Boot server (Linux/FreeBSD)
- Create GRE tunnel with FreeBSD8
- What's cooking for FreeBSD 9