Ravenslay3r wrote:
Quote:
Is there a better or 'right-way' to have this ID returned to me? |
Many ways:
http://dev.mysql.com/doc/mysql/en/Ge...unique_ID.html
But you propably want to use this:
http://dev.mysql.com/doc/mysql/en/mysql_insert_id.html
Because:
"The value of mysql_insert_id() is affected only by statements issued
within the current client connection. It is not affected by statements
issued by other clients."
Which means, that if you have a php script like this:
<?php
open_connection_to_mysql()
insert_row_into_table()
call mysql_insert_id()
insert_row_into_second_table()
close_connection()
?>
It is safe to use mysql_insert_id(), even when there would be multiple
clients using the same script at the same time. Because client would get
the last id from her/his query, not from others queries.
But if you would use "select max(id) from table" or similar, you would
get wrong behavious if two clients would happen to be doing the same
thing at the same time.