LAST_INSERT_ID在UPDATE上不起作用 [英] LAST_INSERT_ID not working on UPDATE
本文介绍了LAST_INSERT_ID在UPDATE上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我使用此SQL:
UPDATE formulare SET EV_id=59, EV_status=5 WHERE EV_id=57 AND ID_uziv=12;SELECT LAST_INSERT_ID();
我将获得0
作为最后的插入ID.
我正在使用php mysqli_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.
我的表formualre
具有auto increment
列,所以我不知道问题出在哪里
my table formualre
has auto increment
column, so I don't know wher the problem is
推荐答案
LAST_INSERT_ID()
将不起作用.
解决方案是这样的:
UPDATE formulare SET EV_id=LAST_INSERT_ID(59), EV_status=5 WHERE EV_id=57 AND ID_uziv=12;SELECT LAST_INSERT_ID();
注意:我想EV_id
是auto_increment主键.
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();
这篇关于LAST_INSERT_ID在UPDATE上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文