note 56329 added to function.mysql-insert-id
| From: | bholbrook at servillian dot com | Date: | Tue, 30 Aug 2005 20:45:29 +0000 |
| Subject: | note 56329 added to function.mysql-insert-id | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94446@lists.php.net to get a copy of this message | ||
An effective way to retrieve the last insert id without fail or having two queries inserted at the
same time causing an unexpected number being returned.
<?
mysql_query("LOCK TABLES apc_forms WRITE");
mysql_query("SET AUTOCOMMIT = 0");
mysql_query("INSERT INTO apc_forms (form_title, form_event_id, form_expirey) VALUES
('title',1,'2005-10-10')");
define('ID',mysql_query("SELECT LAST_INSERT_ID()"));
mysql_query("COMMIT");
mysql_query("UNLOCK TABLES");
?>
----
Manual Page -- http://www.php.net/manual/en/function.mysql-insert-id.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56329
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56329&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56329&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56329&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56329&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56329&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56329&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56329&report=yes
Search -- http://master.php.net/manage/user-notes.php