|
| 1 | +--TEST-- |
| 2 | +Bug #80908: pdo_mysql lastInsertId() return wrong, when table id bigger than the maximum value of int64 |
| 3 | +--SKIPIF-- |
| 4 | +<?php |
| 5 | +if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) die('skip not loaded'); |
| 6 | +require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc'); |
| 7 | +require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); |
| 8 | +MySQLPDOTest::skip(); |
| 9 | +?> |
| 10 | +--FILE-- |
| 11 | +<?php |
| 12 | +require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); |
| 13 | + |
| 14 | +function createDB(): PDO { |
| 15 | + $db = MySQLPDOTest::factory(); |
| 16 | + $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 17 | + $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); |
| 18 | + return $db; |
| 19 | +} |
| 20 | + |
| 21 | +$db = createDB(); |
| 22 | +$db->exec('DROP TABLE IF EXISTS test'); |
| 23 | +$db->exec('CREATE TABLE test (`id` bigint(20) unsigned AUTO_INCREMENT, `name` varchar(5), primary key (`id`)) ENGINE = InnoDB AUTO_INCREMENT=10376293541461622799'); |
| 24 | + |
| 25 | +function testLastInsertId(PDO $db) { |
| 26 | + echo "Running test lastInsertId\n"; |
| 27 | + $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false); |
| 28 | + try { |
| 29 | + $db->exec("insert into test (`name`) values ('bar')"); |
| 30 | + $id = $db->lastInsertId(); |
| 31 | + echo "Last insert id is " . $id . "\n"; |
| 32 | + } catch (PDOException $e) { |
| 33 | + echo $e->getMessage()."\n"; |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +testLastInsertId($db); |
| 38 | +unset($db); |
| 39 | +echo "\n"; |
| 40 | + |
| 41 | +?> |
| 42 | +--CLEAN-- |
| 43 | +<?php |
| 44 | +require __DIR__ . '/mysql_pdo_test.inc'; |
| 45 | +MySQLPDOTest::dropTestTable(); |
| 46 | +?> |
| 47 | +--EXPECT-- |
| 48 | +Running test lastInsertId |
| 49 | +Last insert id is 10376293541461622799 |
0 commit comments