KZ Mai wrote:
Hi, I am developing my own module which uses tables that have auto-increment
fields.
As far as I can tell, drupal uses a single connection for my default configuration.
I don't think i think use last_insert_id without locking because the MySQL DB connection is shared accross requests.
so what should I lock in order to get the correct result from
last_insert_id?
Well I'm not sure it's a good idea using last_insert_id, because such function won't work if users of your module use pgSQL so, I think you should try to keep compatibility between DB.
For this Drupal use db_next_id function that is preferable to mysql auto_incrment fields. So using this you get the next ID for your table and then you can make the INSERT.
Nicolas