第一行记录的标题是:“我和嫂子的那些事儿”
但,列位看官,猜下结果是什么?
array
(
[title] => title
[0] => title
)
为什么会这样?
如果用
select title from tianya_post where id=?
$stmt->bindvalue(1, 1);
可以得到正确的标题的。
回复讨论(解决方案) 字段列表不是参数!
http://blog.csdn.net/fdipzone/article/details/22330345
需要注意的是以下几种情况,pdo并不能帮助你防范sql注入。
不能让占位符 ? 代替一组值,这样只会获取到这组数据的第一个值,如:
select * from table where userid in ( ? );
如果要用in?查找,可以改用find_in_set()实现
$ids = '1,2,3,4,5,6';
select * from table where find_in_set(userid, ?);
不能让占位符代替数据表名或列名,如:
select * from table order by ?;
不能让占位符 ? 代替任何其他sql语法,如:
select extract( ? from addtime) as mytime from table;