RE: [PHP] autoincrementing with mysql
| From: | Vail, Warren | Date: | Wed, 07 Aug 2002 20:46:51 +0000 |
| Subject: | RE: [PHP] autoincrementing with mysql | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-111583@lists.php.net to get a copy of this message | ||
anytime you do an INSERT to a table with an auto increment field (I always
do mine as primary keys as well),
MYSQL will automatically save the auto generated values and give it back to
you in an immediately subsequent call to mysql_insert_id().
mysql_db_query("$DB", $query); // do the insert
$rowid = mysql_insert_id(); // get the assigned auto incr
value
note: don't believe the second function actually does a query (to use your
term).
By-the-way, I also believe this is thread safe within MySQL. (MySQL protects
two inserts from getting the same auto increment value).
hope this helps,
Warren Vail
Tools, Metrics & Quality Processes
-----Original Message-----
From: Alexander Ross [mailto:alexross@bleen.net]
Sent: Wednesday, August 07, 2002 1:28 PM
To: php-general@lists.php.net
Subject: [PHP] autoincrementing with mysql
Is there a way to add a record to a table inwhich one of the columns
auto_incrememnts and return the new increment all at teh same time, or do I
need to add the record and then do a seperate query?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php