我正在尝试在 php 中将 LIKE 与我的 sql 查询一起使用。但它仅在搜索查询完全相同时显示。这是我下面的代码。
<?php
include 'config.php';
$sql = "select name, skill, Location, phone, rating FROM searchResults WHERE skill LIKE :search OR name LIKE :search order by id desc";
try {
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbh->prepare($sql);
// $stmt->bindParam("search", $_GET['search']);
$stmt->bindValue(":search", $_GET['search'], PDO::PARAM_STR);
$stmt->execute();
$employees = $stmt->fetchAll(PDO::FETCH_OBJ);
$dbh = null;
echo '{"items":'. json_encode($employees) .'}';
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
?>
请帮忙
慕后森
扬帆大鱼