note 71604 deleted from function.mysql-insert-id by bjori
| From: | bjori@php.net | Date: | Mon, 11 Jun 2007 21:11:34 +0000 |
| Subject: | note 71604 deleted from function.mysql-insert-id by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127405@lists.php.net to get a copy of this message | ||
Note Submitter: yves at deetune dot com
----
In response to rudolflai at gmail dot com (11-Sep-2006 11:59)
>> Below is a snippet for retriving the next insert id from a mysql table.
>> It functions like the auto_increment option in phpMyAdmin.
Sorry, that's not true!
Your function simply reads the maximum id value of an currently existing row in the table. In case
of deleting the maxium value the next lower id value is used - and that's not the way how
auto_increment works.
So better use the MySQL "SHOW TABLE STATUS" like this:
$SQL = "SHOW
TABLE STATUS
FROM
databaseName
LIKE
'tableName'";
$result = mysql_query($SQL);
$row = mysql_fetch_assoc($result);
$nextInsertId = $row['Auto_increment'];
Yves Vogl