当前位置:编程学习 > php >>

php PDO使用bindValue进行like模糊查询问题

php PDO使用bindValue 用like搜索不到内容

按传统的方法如果sql语句如下:
select * from zhaoxi_net where name like '%?%'  order by id desc limit 0,20
注入参数的值bindValue(1,$name)  
这样会出错,因为为了防止sql注入,其内部将%做了修改。
 
正确方式如下:
select * from  zhaoxi_net where name like ? order by id desc limit 0,20
注入参数的值bindValue(1,'%'.$name.'%');
 
 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,