How reliable is mysqli_insert_id?
Quote:
The mysqli_insert_id() function returns the ID generated by a query on a table with a column having the AUTO_INCREMENT attribute. If the last query wasn't an INSERT or UPDATE statement or if the modified table does not have a column with the AUTO_INCREMENT attribute, this function will return zero.
What if you did an insert or update that failed?
What I'm doing is looping through a LOT of records, taking the values I get, modify it and insert into another table.
At the moment I rely on mysqli_insert_id to see if the insert was successful, but what if the insert failed for whatever reason? Will mysqli_insert_id return 0 or still hold the id of the last successful insert?
I cannot really check if the insert was performed by doing a query as there will be records (say cities) that will be duplicate (as more than one country have the same city).
Re: How reliable is mysqli_insert_id?
If a query fails then mysql_query will return FALSE and calling mysql_error will give you the error condition. Use this to check whether or not your record insertion was successful.