怎么用?标记以绑定PDO中的值?

时间:2014-08-21 09:14:24

标签: php mysql pdo

通常你会有这样的查询:

$qry = $this->db->prepare(" SELECT * FROM `table` WHERE status = :status ");
$qry->execute(array(':status'=>'whatever value'));

所以我想做的是这样的事情:

$qry = $this->db->prepare(" SELECT * FROM `table` WHERE status = ? ");
$qry->execute(array('whatever value'));

是否有某种属性可以设置来完成此任务?

1 个答案:

答案 0 :(得分:4)

$sth = $dbh->prepare('SELECT name, colour, calories
    FROM fruit
    WHERE calories < ? AND colour = ?');
$sth->execute(array(150, 'red'));
$red = $sth->fetchAll();