Results 1 to 2 of 2

Thread: How reliable is mysqli_insert_id?

Threaded View

  1. #1

    Thread Starter
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Resolved How reliable is mysqli_insert_id?

    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).
    Last edited by StrangerInBeijing; Jun 26th, 2008 at 08:06 PM. Reason: Resolved
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width