note 65848 added to function.mysql-insert-id
| From: | james dot baxter at nospamplease dot com | Date: | Tue, 09 May 2006 00:09:42 +0000 |
| Subject: | note 65848 added to function.mysql-insert-id | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-110911@lists.php.net to get a copy of this message | ||
Have had many people coming to me with issues regarding last_insert_id and mysql_insert_id() etc
This is a very simple solution that caters for most. As you can see it gets the last auto inc from
the field, in this case, ID.
mysql_query("LOCK TABLES art WRITE");
mysql_query("INSERT INTO table (....) VALUES (....)");
$result = mysql_query("SELECT MAX(ID) AS LAST_ID FROM table");
$result = mysql_fetch_array($result);
mysql_query("UNLOCK TABLES");
echo "Last ID#" . $result[LAST_ID];
----
Server IP: 84.18.202.180
Probable Submitter: 84.9.112.92
----
X-Spam-Status: No, hits=3.8 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
UPPERCASE_25_50 autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.mysql-insert-id.php
Edit -- http://master.php.net/note/edit/65848
Del: integrated -- http://master.php.net/note/delete/65848/integrated
Del: useless -- http://master.php.net/note/delete/65848/useless
Del: bad code -- http://master.php.net/note/delete/65848/bad+code
Del: spam -- http://master.php.net/note/delete/65848/spam
Del: non-english -- http://master.php.net/note/delete/65848/non-english
Del: in docs -- http://master.php.net/note/delete/65848/in+docs
Del: other reasons-- http://master.php.net/note/delete/65848
Reject -- http://master.php.net/note/reject/65848
Search -- http://master.php.net/manage/user-notes.php