簡體   English   中英

PHP PDO Mysql錯誤1064插入

[英]Php PDO Mysql error 1064 inserting

確實要與這些該死的語法錯誤作斗爭。 如果有人看到這有什么問題,請告訴我:

請求參數

INSERT INTO Categories (ParentId,Title,Desc) VALUES (?,?,?)

數組的Print_R已傳遞

Array
(
    [0] => 1
    [1] => Lolcats
    [2] => an entire category dedicated to the language, lolcats!
)

錯誤:

<b>Fatal error</b>:  Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Desc) VALUES ('1','Lolcats','an entire category dedicated to the language, lolca' at line 1' in /usr/www/maxtingle/Blog/System/Core/Functions.php:168
Stack trace:
#0 /usr/www/maxtingle/Blog/System/Core/Functions.php(168): PDOStatement-&gt;execute(Array)
#1 /usr/www/maxtingle/Blog/System/Core/Category.php(12): Functions\Database-&gt;Insert('(ParentId,Title...', 3, Array)
#2 /usr/www/maxtingle/Blog/System/Category.php(9): Categories::CreateCategory(Object(CategoryIns))
#3 [internal function]: Category::Create()
#4 /usr/www/maxtingle/Blog/index.php(52): call_user_func_array(Array, Array)
#5 {main}
  thrown in <b>/usr/www/maxtingle/Blog/System/Core/Functions.php</b> on line <b>168</b><br>

Desc是關鍵字,要將其用作列名,請使用反引號

INSERT INTO Categories (ParentId,Title,`Desc`) VALUES (?,?,?)

最佳做法是對所有表名和列名使用反引號,這樣您就永遠不會遇到關鍵字問題。

INSERT INTO `Categories` (`ParentId`,`Title`,`Desc`) VALUES (?,?,?)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM