选择最后一个插入ID [英] Select last insert id
问题描述
我正在插入一条记录,我想使用插入的最后一条记录的ID. 这是我尝试过的:
I am inserting a record and i want to use the id of the last record inserted. This is what i have tried:
$sql =
'INSERT INTO customer
(first_name,
last_name,
email,
password,
date_created,
dob,
gender,
customer_type)
VALUES(:first_name,
:last_name,
:email,
:password,
:date_created,
:dob,
:gender,
:customer_type)' . ' SELECT LAST_INSERT_ID()' ;
我遇到了错误:
您的SQL语法有误;检查与您的MySQL对应的手册
正确的语法的服务器版本,以在"SELECT LAST_INSERT_ID()"附近使用.
谁能告诉我我的错误在哪里?
谢谢!
I am getting the error:
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 'SELECT LAST_INSERT_ID()'.
Can anyone show me where is my mistake?
Thanks!
推荐答案
签出 mysql_insert_id() >
mysql_query($sql);
$id = mysql_insert_id();
在mysql_query()命令中执行INSERT语句后运行该函数时,其结果将是刚创建的行的ID.
When that function is run after you've executed your INSERT statement in a mysql_query() command its result will be the ID of the row that was just created.
这篇关于选择最后一个插入ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!