Symfony - Custom Query + Set Parameter
Monday, May 14, 2012
$pdo = Doctrine_Manager::connection()->getDbh();
$sql = 'select id, name, descr, created_at from news where name like :name-value and descr like :descr-value';
$stmt = $pdo->prepare($sql);
$params = array("name-value" => $name, "descr-value" => '%' . $descr . '%');
$stmt->execute($params);
// or
$sql = 'select id, name, descr, created_at from news where name like ? and descr like ?';
$stmt = $pdo->prepare($sql);
$params = array($name, '%' . $descr . '%');
$stmt->execute($params);
return $stmt->fetchAll();
0 comments:
Post a Comment