我已经阅读了多个关于如何编写这些查询的示例,但我正在努力让这个特定的喜欢在使用时运行bindParam
这是匹配以a开头的用户名的正确方法吗?
$term = "a";
$term = "'$term%'";
$sql = "SELECT username
FROM `user`
WHERE username LIKE :term
LIMIT 10";
$core = Connect::getInstance();
$stmt = $core->dbh->prepare($sql);
$stmt->bindParam(':term', $term, PDO::PARAM_STR);
$stmt->execute();
$data = $stmt->fetchAll();