Returning last inserted id from MySql

后端 未结 2 570
庸人自扰
庸人自扰 2021-01-07 01:40

I\'m having a bit of trouble with the following query:

START TRANSACTION;

SET @LASTID = 0;

INSERT INTO `Accounts` (         


        
相关标签:
2条回答
  • 2021-01-07 02:01

    use

     SELECT LAST_INSERT_ID();
    

    http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id

    0 讨论(0)
  • 2021-01-07 02:20

    Change the last statement into:

    SELECT CAST(@LASTID AS integer) as last_id_from_accounts;
    
    0 讨论(0)
提交回复
热议问题