PDO SELECT LIKE 没有找到任何东西

PDO SELECT LIKE Is Not finding anything

大家好,我正在尝试寻找标题中有类似 Angel 的内容,但由于某种原因,它没有返回任何内容,例如,我得到了一个带有

的电影标题

黑衣女人 2:死亡天使 (2014)

但它一直说没有发现任何帮助都非常感谢!

<?php
require_once("../connection/config.php");
global $instance;

$search="Angel";
$query = $instance->prepare("select * from movies where title LIKE '%$search%'  LIMIT 0 , 10");
$query->bindValue(1, "%$search%", PDO::PARAM_STR);
$query->execute();

         if (!$query->rowCount() == 0) {
                echo "Search found :<br/>";
                echo "<table>";
                echo "<tr>Movies</tr>";
            while ($results = $query->fetch()) {
                echo "<tr>";
                echo $results['title'];
                echo "</tr>";
            }
                echo "</table>";
        } else {
            echo 'Nothing found';
        }
?>

这应该是 -

$query = $instance->prepare("select * from movies where title LIKE :val  LIMIT 0 , 10");
$query->bindValue(':val', "%$search%", PDO::PARAM_STR);

尝试

$query = $instance->prepare("select * from movies where title LIKE :search LIMIT 0, 10"); $query->bindParam(':search, '%'.$search.'%'); $query->execute();

我认为您不能在绑定时将变量插入引号中,否则它会被转换为字符串。我相信您需要事先添加通配符。

$search="%Angel%";
$query = $instance->prepare("select * from movies where title LIKE ? LIMIT 0 , 10");
$query->bindValue(1, $search, PDO::PARAM_STR);