PHP & MySQL get value of auto_increment field of new data
| From: | Tom Harris | Date: | Wed, 08 Nov 2000 18:06:43 +0000 |
| Subject: | PHP & MySQL get value of auto_increment field of new data | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-24353@lists.php.net to get a copy of this message | ||
Hi folks,
The dumb newbie has a question...
I use a PHP script to take data from a web form and insert it into a MySQL
database. The database has an id field that is AUTO_INCREMENTing and the
primary key. I want to be able to retrieve the id field that belongs to the
record I just inserted.
My first thought was to just pull out the highest value in the id field, but
what happens if two people are entering data at the same time? I'm sure
this is unlikely, but I would think there would be another way.
I also thought about sending a query to match the data just entered, but the
only field that would be unique would be a giant text field that is probably
not a good idea to perform searches on.
Any suggestions?
Thanks,
-T