首页 > PHP > PHP中使用PDO进行like模糊查询

PHP中使用PDO进行like模糊查询

2014年3月7日 发表评论 阅读评论    

开始的代码,返回的是空

$name = ‘北京’;

$sql = “SELECT * FROM table WHERE name like ‘?%'”;

$stmt = $dbh->prepare($sql);

$stmt->execute(array($name));

$rs = $stmt->fetchAll();

后来改的代码,返回也是空

$name = ‘北京’;

$sql = “SELECT * FROM table WHERE name like ‘?'”;

$stmt = $dbh->prepare($sql);

$stmt->execute(array($name.’%’));

$rs = $stmt->fetchAll();

最后的代码就成功了

$name = ‘北京’;

$sql = “SELECT * FROM table WHERE name like ?”;

$stmt = $dbh->prepare($sql);

$stmt->execute(array($name.’%’));

$rs = $stmt->fetchAll();

分类: PHP 标签: , ,
1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 3.00 out of 5)
Loading...
  1. 本文目前尚无任何评论.
您必须在 登录 后才能发布评论.