现在使用PDO进行数据库操作,已经是标配了,在使用过程中,需要注意一下问题
注意要点
- 参数绑定不能应用到表名上
//错误
$sth = $dbh->prepare('SELECT name, colour, calories FROM ? WHERE calories < ?');
//正确
$sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < ?');
- 参数绑定不能应用到列名
//错误
$sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE ? < ?');
//正确
$sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < ?');