Getting key of row just inserted into mySQL
| From: | Grant Boggs | Date: | Wed, 22 Aug 2001 23:24:20 +0000 |
| Subject: | Getting key of row just inserted into mySQL | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-11692@lists.php.net to get a copy of this message | ||
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