mysql update last_insert_id,LAST_INSERT_ID在UPDATE上不起作用

if I use this SQL:

UPDATE formulare SET EV_id=59, EV_status=5 WHERE EV_id=57 AND ID_uziv=12;SELECT LAST_INSERT_ID();

I will get 0 as last insert id.

I'm using php mysqli_insert_id and here is said that:

The mysqli_insert_id() function returns the ID generated by a query

on a table with a column having the AUTO_INCREMENT attribute.

If the last query wasn't an INSERT or UPDATE statement

or if the modified table does not have a column with the AUTO_INCREMENT attribute,

this function will return zero.

my table formualre has auto increment column, so I don't know wher the problem is

解决方案

LAST_INSERT_ID() won't work if no new auto increment value was created.

The solution is something like this:

UPDATE formulare SET EV_id=LAST_INSERT_ID(59), EV_status=5 WHERE EV_id=57 AND ID_uziv=12;SELECT LAST_INSERT_ID();

Note: I guess, that EV_id is the auto_increment primary key.

Otherwise you should do a query like:

UPDATE formulare SET key_col = LAST_INSERT_ID(key_col), EV_id=59, EV_status=5 WHERE EV_id=57 AND ID_uziv=12;SELECT LAST_INSERT_ID();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值