note 54214 added to function.mysql-insert-id
| From: | mark at dreamjunky dot com | Date: | Mon, 27 Jun 2005 14:04:42 +0000 |
| Subject: | note 54214 added to function.mysql-insert-id | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91022@lists.php.net to get a copy of this message | ||
Responding to ed at is-cool dot net...
"Put something else in place such as "select count( id ) from table" before and after
the mysql_insert_id() call to ensure that a row was inserted."
Sound advice, but that method isn't entirely necessary. Just check the return value of
mysql_query which, for inserts, will be false on error.
if (mysql_query($insert_query))
{
// select your insert ID safely
}
else
{
// error handling, etc
}
Mark
----
Manual Page -- http://www.php.net/manual/en/function.mysql-insert-id.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54214
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54214&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54214&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54214&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54214&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54214&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54214&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54214&report=yes
Search -- http://master.php.net/manage/user-notes.php