In raw PHP I'd do it like this:
$sth = $dbh->prepare("SELECT * FROM tags WHERE tag=:tag");
foreach ( $tags as $tag ) {
$sth->bindValue(':tag', $tag);
$sth->execute(); // followed by fetch, etc.
}
In CakePHP I'd have to use the native find()
function:
foreach ( $tags as $tag ) {
$this->Tag->find('first', array(
'conditions' => array(
'tag' => $tag,
),
));
}
I'm pretty sure this will result in CakePHP firing a set of separate database queries which won't utilise the benefits of having the prepared statement in place.
Is there any way I could force CakePHP to do that without modifying the core?
UPDATE There is a way to call $this->getDataSource()
directly but I'm looking for a way to keep using the find()
method, if possible, because it handles contains automatically and the code for those complex queries using joins and all just looks more elegant that way.