PDO Mysql错误1064

时间:2013-07-06 03:14:12

标签: php mysql

查询(回声)

DELETE * FROM BlogPosts WHERE Id=?

错误

Fatal error: 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 '* FROM BlogPosts WHERE Id='6'' at line 1' in /usr/www/maxtingle/Blog/System/Core/Functions.php:177 Stack trace: #0 /usr/www/maxtingle/Blog/System/Core/Functions.php(177): PDOStatement->execute(Array) #1 /usr/www/maxtingle/Blog/System/Core/BlogPost.php(201): Functions\Database->Delete('*', 'Id=?', Array) #2 /usr/www/maxtingle/Blog/System/Blog.php(102): BlogPost->Delete() #3 [internal function]: Blog::DeletePost('6') #4 /usr/www/maxtingle/Blog/index.php(52): call_user_func_array(Array, Array) #5 {main} thrown in /usr/www/maxtingle/Blog/System/Core/Functions.php on line 177

2 个答案:

答案 0 :(得分:2)

DELETE总是会删除整行,因此指定要删除的字段毫无意义。

你想:

DELETE FROM BlogPosts WHERE Id=?

答案 1 :(得分:2)

您不需要*,删除整行:

DELETE FROM BlogPosts WHERE Id=?