13
我讀過這些查詢應該怎麼寫多個例子,但我努力讓這個特定喜歡用bindParam
在bindParam用於MySQL的PDO查詢
時運行請問這是正確的方式使用LIKE匹配以?開頭的用戶名
$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();
以下是示例代碼:https://gist.github.com/arsho/a203e7bc156ea566587361a76038f020 – arsho