Search code examples
phpmysqlauto-increment

MYSQL Pull auto increment value


Is it possible to add a entry to a database that has an auto increment column and pull the value of the auto increment number as you enter it?

The company I work for is accepting leads, and when a lead comes in, it has to be assigned a unique customer number that can never be duplicated. I would love to use mysql auto increment, but I would need to pull the value it stores as the lead is entered so it can go out to lenders API's along with the unique customer number.

Any help??!!


Solution

  • Yes, in mysql itself you can use the function LAST_INSERT_ID() or from php you can use mysqli_insert_id() or PDO::lastInsertId() to return the last value automatically inserted for an auto-increment column by a previous query.

    See: php documentation, mysql documentation