【发布时间】:2021-12-19 22:21:59
【问题描述】:
我在编码方面非常基础,并且有以下 sn-p 代码
$connection = new PDO($dsn, $username, $password, $options);
$sql = "SELECT *
FROM birds
WHERE Species Like :Species";
$Species = $_POST['Species'];
$statement = $connection->prepare($sql);
$statement->bindParam(':Species', $Species, PDO::PARAM_STR);
$statement->execute();
$result = $statement->fetchAll();
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
}
只要拼写正确,它就可以正常工作。我如何在搜索功能中添加通配符,因为我尝试过的所有变体似乎都不起作用。
我还想知道如何让它根据表单中输入的结果在几列中查找数据。即从一个文本字段中搜索姓名或位置或年龄。
【问题讨论】:
-
您尝试了哪些变体?
-
通配符不会为模糊搜索找到拼写错误的搜索
-
这能回答你的问题吗? pdo prepared statements with wildcards