有什么方法可以转换
$term = $_GET['p'];
$stmt = $dbh->prepare("
SELECT *
FROM posts
WHERE heading LIKE '%$term%'
OR full_text LIKE '%$term%'
LIMIT 0 , 30
");
$stmt->execute();
$answer = $stmt->fetch(PDO::FETCH_ASSOC);
进入类似的东西
$term = "'%" . $_GET['p'] . "%'";
$stmt = $dbh->prepare("
SELECT *
FROM posts
WHERE heading LIKE :term
OR full_text LIKE :term
LIMIT 0 , 30
");
$stmt->bindParam(":term", $term);
$stmt->execute();
$answer = $stmt->fetch(PDO::FETCH_ASSOC);
这样我就可以在查询中使用bindParam(":term", $term);
而不是'%$term%'
?
我已经看过这些Using LIKE in bindParam for a MySQL PDO Query和 Mysql, PDO - Like statement not working using bindParam。但是他们没有为我的问题提供任何正确的答案。