0
什么是错我的查询?我试图插入带有一个查询既执行INSERT语句,但我得到这个错误:MySQL错误1064 - 做一个查询中两个INSERT语句;这有什么问题?
Error 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 'INSERT INTO todo (title, slug, description, user_id) VALUES (?, ?, ?, ?); ' at line 2
我已经阅读了错误,但我没有看到什么不对的INSERT语句,我是什么在这里失踪?
BEGIN;
INSERT INTO todo (title, slug, description, user_id)
VALUES (?, ?, ?, ?);
SET @last_insert_id = LAST_INSERT_ID();
INSERT INTO todo_category (todo_id, category_id)
VALUES (@last_insert_id, ?),
(@last_insert_id, ?),
(@last_insert_id, ?);
COMMIT;
在执行查询之前,问号将被消耗到值中。
您似乎正在使用['MS SQL'](https://msdn.microsoft.com/en-us/library/ms188929.aspx)语法,您应该使用['MySQL'](https:/ /dev.mysql.com/doc/refman/5.7/en/commit.html)语法。 –
语法正确。确保在执行前真正替换问号。 –
你是如何试图执行呢?如果它是PHP(或另一个不允许多个查询的API),[this](http://stackoverflow.com/questions/12679241/php-mysql-begin-commit-not-working)可能是你的问题。 – Uueerdo