在mysqli中输出Inserted.row [英] OUTPUT Inserted.row in mysqli
问题描述
我有以下sql表:
id | email | fbid
id|email|fbid
我执行查询时
INSERT INTO users(email,fbid) VALUES('randomvalue','otherrandomvalue')
我想获取插入行的ID.为此,我尝试像这样编辑查询:
I want to get the id of the inserted row. To do so, I've tried to edit the query like this:
INSERT INTO users(email,fbid) VALUES('randomvalue','otherrandomvalue') OUTPUT Inserted.id
但是我得到了:
1064-您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册以使用正确的语法 在第1行的"OUTPUT Inserted.id"附近
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 'OUTPUT Inserted.id' at line 1
可能是什么问题?
推荐答案
不幸的是(据我所知) mysql 不支持output
,因为
Unfortunately (as far as I can tell) mysql does not support output
as sql-server does.
您确实可以选择要在单行插入操作中完成的操作(假设使用auto_increment主键):
You do have an option for what you're trying to accomplish in a single row insert (assuming auto_increment primary key):
SELECT LAST_INSERT_ID();
不幸的是,此操作 在批量插入的情况下将无法工作-尽管在您的情况下您没有用(至少在您的示例中不是),所以这应该是美好的.
This unfortunately would not work in the case of a batch insert - though in your case you are not (at least not in your example), so this should be fine.
这篇关于在mysqli中输出Inserted.row的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!