存档

2014年3月 的存档

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...