note 93622 deleted from function.mysql-insert-id by cmb

From: Date: Sun, 16 Feb 2020 13:32:41 +0000
Subject: note 93622 deleted from function.mysql-insert-id by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-214121@lists.php.net to get a copy of this message
Note Submitter: RPaseur at NationalPres dot org ---- 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) ?>

« previous php.notes (#214121) next »