in reply to last_insert_id did not work

Note that last_insert_id has quite a few caveats including:
For some drivers the value may only be available if placeholders have not been used (e.g., Sybase, MS SQL). In this case the value returned would be from the last non-placeholder insert statement.

For this reason I prefer to get the database do provide the information rather than the driver.

my ($_cinsert) = $dbh->selectrow_array("SELECT LAST_INSERT_ID()");

Replies are listed 'Best First'.
Re^2: last_insert_id did not work
by bizactuator (Sexton) on Mar 27, 2021 at 22:36 UTC
    Doing it that way, would I have to tell it which table? or does it already know?

    Example:
    $_chinsert = $dbh->selectrow_array("SELECT LAST_INSERT_ID()");
    that does not specify which table, if the site is busy, could that not get something else from someone else?

    Thanks,
    -Richard
      Doing it that way, would I have to tell it which table? or does it already know?

      No need to specify the table. LAST_INSERT_ID() returns the ID of the last insert made on a table with an auto-increment column by the session calling the function.

      could that not get something else from someone else?

      No because the function only returns the information from the current session.

        I understand, thank you much!

        Thanks again.