Welcome Guest, Not a member yet? Register   Sign In
How to get id after insert data
#14

[eluser]WanWizard[/eluser]
@juanvillages,

You haven't read my post.

The insert_id is a connection property. When user #1 inserts a record, the insert_id property is populated by the driver for user #1's connection, and the table for which the record was inserted. When user #2 inserts a record in the same table, the same happens, but for that connection. These are two different fields, and populated directly after the insert. In other words, it is not a single value kept per table.

When you then request the insert id, the value stored in the connection is returned. This is still the value stored after user #1's insert, and is unaffected by other inserts. It will only be overwritten when user #1 inserts another record.

You don't need a lock for this. You need a lock if you manually try to do this, using 'SELECT MAX(record_id) FROM table', adding one to the result, and then insert the record. Because between the select and the insert someone else could have inserted a record.


Messages In This Thread
How to get id after insert data - by El Forum - 07-19-2009, 02:39 AM
How to get id after insert data - by El Forum - 07-19-2009, 03:19 AM
How to get id after insert data - by El Forum - 07-19-2009, 04:11 AM
How to get id after insert data - by El Forum - 07-19-2009, 04:56 AM
How to get id after insert data - by El Forum - 07-19-2009, 06:39 AM
How to get id after insert data - by El Forum - 07-19-2009, 10:05 AM
How to get id after insert data - by El Forum - 07-19-2009, 11:32 AM
How to get id after insert data - by El Forum - 07-19-2009, 11:42 AM
How to get id after insert data - by El Forum - 09-11-2010, 02:21 PM
How to get id after insert data - by El Forum - 09-11-2010, 02:52 PM
How to get id after insert data - by El Forum - 09-11-2010, 03:26 PM
How to get id after insert data - by El Forum - 09-11-2010, 03:29 PM
How to get id after insert data - by El Forum - 09-12-2010, 02:09 AM
How to get id after insert data - by El Forum - 09-12-2010, 04:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB