![](/img/trans.png)
[英]Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation:
[英]Uncaught PDOException: SQLSTATE Syntax error or access violation
當我使用 select 時出現此錯誤
$listchat = $pdo->prepare("SELECT * FROM listchat WHERE ?, userkey=?, ORDER BY idroom ASC LIMIT ?");
然后
$num = 10;
$gid = 0;
$listchat->execute([$gid,$userKey,$num]);
我收到帖子標題錯誤,我錯在哪里?
致命錯誤:未捕獲的 PDOException:SQLSTATE[42000]:語法錯誤或訪問沖突:1064 您的 SQL 語法有錯誤; 查看與您的 MariaDB 服務器版本相對應的手冊,了解在“userkey='66756”附近使用的正確語法,
您缺少要與$gid
進行比較的列。 條件使用AND
或OR
組合,而不是逗號。
$listchat = $pdo->prepare("
SELECT *
FROM listchat
WHERE gid = ? AND userkey=?
ORDER BY idroom ASC
LIMIT ?");
您還需要使用bindParam
或bindValue
為LIMIT
提供一個值,因此您可以指定它應該被視為 integer,而不是字符串。
$listchat->bindValue(1, $gid);
$listchat->bindValue(2, $userKey);
$listchat->bindValue(3, $num, PDO::PARAM_INT);
$listchat->execute();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.