mysql update obtain the primary key

mysql update获取主键
<pre>
SET @update_id := 0;
UPDATE mobantestinfo1 SET info2 = 'value', id = (SELECT @update_id := id)
WHERE info1 = '23a' LIMIT 1;
SELECT @update_id;
</pre>

The general idea is to first declare a user variable @update_id, then you have to update more than one field at the time of update data is currently updated to the current primary key primary key value (in fact, is not updated), update the primary key field is not an end, just to the current primary key value assigned to @update_id, is the phrase: (SELECT @update_id: = id)


PDO only if it is run separately between mysql statement variable is not shared by multiple users such as a user saved variables as well as variables read variable is empty

Guess you like

Origin www.cnblogs.com/newmiracle/p/11856281.html