在不使用 mysql_insert_id() 的情况下获取最后插入记录的 id [英] get id of last inserted record without using mysql_insert_id()
问题描述
$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()' ;
谁能告诉我语法是否正确?我在使用 mysql_insert_id 时遇到问题,这就是为什么我使用 SELECT LAST_INSERT_ID()
Can anyone tell me if the syntax is right? I am having problems using mysql_insert_id that is why i am using SELECT LAST_INSERT_ID()
错误信息:mysql_insert_id() [function.mysql-insert-id]: 用户 'ODBC'@'localhost' 的访问被拒绝
the error message: mysql_insert_id() [function.mysql-insert-id]: Access denied for user 'ODBC'@'localhost'
推荐答案
如果在两个查询之间添加结束 ;
就可以了(至少 MySQL 会接受,我不知道如果 PHP 会抱怨).但是,如上所述,它不是很好的代码,如果将其分开,将成为竞争条件.用 mysql_insert_id()
找出你的问题,然后像设计的那样使用它.
It will work if you add the closing ;
between the two queries (at least MySQL will accept it, I don't know if PHP will complain). But, as above, it's not very good code and, if you separate it, will be a race condition. Figure out your kinks with mysql_insert_id()
and use that like it's designed for.
这篇关于在不使用 mysql_insert_id() 的情况下获取最后插入记录的 id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!