[UPHPU] mySQL Primary Keys

Jacob Hanson jacdx at jacobhanson.com
Tue Jun 29 23:16:11 MDT 2004


Tuesday, June 29, 2004, 10:51:27 PM, you wrote:
>  LAST_INSERT_ID() and/or mysql_insert_id() will work for you.
> According to the MySQL Manual they are only affected by the current
> client connection. They won't be affected by other users.

> If you're id is autoincremented you do your insert statement and then
> something like:

> $mynewID = LAST_INSERT_ID();

> Try reading the following:
> http://dev.mysql.com/doc/mysql/en/Getting_unique_ID.html
> http://dev.mysql.com/doc/mysql/en/mysql_insert_id.html

That's right, good catch David. The issues I mentioned only apply in
environments that persist connections, and aren't normally used
in/with PHP.

Note that LAST_INSERT_ID() is a MySQL function, so it works in a
query instead of PHP code.

Jacob





More information about the UPHPU mailing list