2013-07-07 57 views
1

真的很难与这些该死的语法错误。如果任何人都可以看看有什么不对的请告诉我:Php PDO Mysql错误1064插入

查询字符串

阵列的
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> 

回答

4

Desc是一个关键词。要将其作为列名使用反引号

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

唉!非常感谢。 – user1763295

4

最好的做法是对所有表名和列名使用反标记,这样您就永远不会遇到关键字问题。

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