note 93622 added to function.mysql-insert-id
| From: | RPaseur at NationalPres dot org | Date: | Fri, 18 Sep 2009 18:48:37 +0000 |
| Subject: | note 93622 added to function.mysql-insert-id | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-160837@lists.php.net to get a copy of this message | ||
Apparently the value returned by mysql_insert_id() may be correct for BIGINT auto_increment keys
below the value of INT, but it may wrap to negative when the BIGINT auto_increment passes the
largest signed value of INT. A timebomb for very large tables...
PHP 5.2.10, MySQL 5.0.81, assume the connection and selection...
<?php
// CREATE A TABLE AND ALTER IT TO A HIGH INDEX NUMBER
$sql = "CREATE TEMPORARY TABLE noise ( id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY )
ENGINE=MEMORY";
if (!$res = mysql_query($sql)) die(mysql_error());
$sql = "ALTER TABLE noise AUTO_INCREMENT = 2147483646";
if (!$res = mysql_query($sql)) die(mysql_error());
// INSERT DATA TO ADD TO THE AUTO_INCREMENT INDEX
$kount = 0;
while ($kount < 3)
{
$sql = "INSERT INTO noise () VALUES ()";
if (!$res = mysql_query($sql)) die(mysql_error());
$nid = mysql_insert_id($dbcx);
var_dump($nid);
$kount++;
}
// PRODUCES THIS
// int(2147483646)
// int(2147483647)
// int(-2147483648)
----
Server IP: 64.71.164.2
Probable Submitter: 74.9.128.130
----
Manual Page -- http://www.php.net/manual/en/function.mysql-insert-id.php
Edit -- https://master.php.net/note/edit/93622
Del: integrated -- https://master.php.net/note/delete/93622/integrated
Del: useless -- https://master.php.net/note/delete/93622/useless
Del: bad code -- https://master.php.net/note/delete/93622/bad+code
Del: spam -- https://master.php.net/note/delete/93622/spam
Del: non-english -- https://master.php.net/note/delete/93622/non-english
Del: in docs -- https://master.php.net/note/delete/93622/in+docs
Del: other reasons-- https://master.php.net/note/delete/93622
Reject -- https://master.php.net/note/reject/93622
Search -- https://master.php.net/manage/user-notes.php