i have a table in the database contains _id column which is the primary key for this table , actually this column value is set by the auto increment approach , is there any safe way to get the value that the auto increment value given to the row i when i make the insert ??? i saw a solution says :” call mysql_insert_id() immediately after your insert query.” is it safe to use( i.e does it get a wrong value if the same script in different thread )??? if not is there any way to make a synchronized block in php?
i have a table in the database contains _id column which is the primary
Share
as far as I know, the id returned from mysql_insert_id is the auto increment id from the last insert query for the current connection (mysql_connect) to the sql database. The only reason for having to call it right after the query is that if you run two insert queries right after each other, mysql_insert_id returns just the last query. It wouldn’t be reliably possible to get the id from the first query. Also, it gets the id from the last query, so if you did an insert then update, then ran mysql_insert_id. It would return 0 because the last query (update) isn’t an insert.
Also, php just calls the mysql function mysql_insert_id. From the mysql manual: