note 61340 added to function.mysql-insert-id
| From: | johnk dot at osu1 dot php dot net | Date: | Tue, 31 Jan 2006 22:55:28 +0000 |
| Subject: | note 61340 added to function.mysql-insert-id | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-102790@lists.php.net to get a copy of this message | ||
Be careful when using "insert ignore". If the unique index already exists, the record will
not be added, but it WILL give you the id of the next auto_increment value even though it
didn't create it.
<?php
$sql = "insert ignore into sometable set num=10";
mysql_query($sql) or die();
echo mysql_affected_rows()."<br>";
echo mysql_insert_id()."<br><br>";
// same record, database is unique on 'num'
$sql = "insert ignore into sometable set num=10";
mysql_query($sql) or die();
echo mysql_affected_rows()."<br>";
echo mysql_insert_id()."<br><br>";
?>
would give:
1
116372
0
116373
----
Server IP: 64.71.164.2
Probable Submitter: 68.94.200.18
----
Manual Page -- http://www.php.net/manual/en/function.mysql-insert-id.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61340
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61340&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61340&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61340&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61340&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61340&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61340&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61340&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61340&report=yes
Search -- http://master.php.net/manage/user-notes.php