gpt4 book ai didi

Php PDO Mysql插入错误1064

转载 作者:行者123 更新时间:2023-11-29 03:56:55 24 4
gpt4 key购买 nike

真的在与这些该死的语法错误作斗争。如果有人能看出这有什么问题,请告诉我:

查询字符串

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 (?,?,?)

关于Php PDO Mysql插入错误1064,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17508713/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com