dtc9222 2010-02-16 07:26
浏览 231
已采纳

不使用mysql_insert_id()获取最后插入记录的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()' ; 

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()

the error message: mysql_insert_id() [function.mysql-insert-id]: Access denied for user 'ODBC'@'localhost'

  • 写回答

4条回答 默认 最新

  • doukuai3822 2010-02-16 07:32
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面