这是我的尝试:
$query = $database->prepare('SELECT * FROM table WHERE column LIKE "?%"');
$query->execute(array('value'));
while ($results = $query->fetch())
{
echo $results['column'];
}
Run Code Online (Sandbox Code Playgroud) 我已经阅读了关于如何编写这些查询的多个示例,但我正在努力使这个特定的类似于在使用时运行 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();
Run Code Online (Sandbox Code Playgroud)