This has been covered countless times on the list... :) http://www.php.net/manual/en/function.mysql-insert-id.php -----Original Message----- From: Grant Boggs [mailto:[EMAIL PROTECTED]] Sent: Wednesday, August 22, 2001 7:24 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] Getting key of row just inserted into mySQL What's the best way to get the primary key of a row just inserted into a mySQL database? If the primary key is autoincrement, I insert a row. It's successful, but now how to do I read back the key of this table? Right now I'm adding a md5 hash of the session id into the row I'm inserting, and then will read that row back. But this seems clunky.... Should I just go for a "keytable" approach? Where I have a no autoincrement fields and just a table that holds the key value for each table. When I insert a row, I lock the row of the keytable I'm inserting int, update it's value, write it back, then use that key to insert into the main table? -- ================== Grant Boggs http://www.cornersonesoftware.ws -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]