LIKE查询不起作用, 它只输出空白。
$stmt = $dbo->prepare("SELECT * FROM hotels WHERE h_country=:c LIKE '%m%'");
$stmt->bindValue(":c", "malaysia", PDO::PARAM_STR);
$stmt->execute();
答案 0 :(得分:1)
你的SQL语法错了,不确定你想要获得什么,但是正确的是:
SELECT * FROM hotels WHERE h_country LIKE '%' || :c || '%';
--OR
SELECT * FROM hotels WHERE h_country = :c AND <your_column_here> LIKE '%m%';
答案 1 :(得分:0)
更改
$stmt = $dbo->prepare("SELECT * FROM hotels WHERE h_country=:c LIKE '%m%'");
到
$stmt = $dbo->prepare("SELECT * FROM hotels WHERE h_country LIKE '%m%'");
您要么将值与LIKE函数进行比较,要么与变量&#39;:c&#39;进行比较。它的一个或另一个。
如果您想同时使用以下内容:
$stmt = $dbo->prepare("SELECT * FROM hotels WHERE h_country=:c OR h_country LIKE '%m%'");