PHP中使用PDO进行like模糊查询
开始的代码,返回的是空
$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();
最近评论