xref: /php-src/ext/pdo_mysql/tests/bug80908.phpt (revision 4bb75d56)
1--TEST--
2Bug #80908: pdo_mysql lastInsertId() return wrong, when table id bigger than the maximum value of int64
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once __DIR__ . '/inc/mysql_pdo_test.inc';
8MySQLPDOTest::skip();
9?>
10--FILE--
11<?php
12require_once __DIR__ . '/inc/mysql_pdo_test.inc';
13
14function 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('CREATE TABLE test_80908 (`id` BIGINT(20) UNSIGNED AUTO_INCREMENT, `name` VARCHAR(5), PRIMARY KEY (`id`)) ENGINE = InnoDB AUTO_INCREMENT=10376293541461622799');
23
24function testLastInsertId(PDO $db) {
25    echo "Running test lastInsertId\n";
26    $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
27    try {
28        $db->exec("INSERT INTO test_80908 (`name`) VALUES ('bar')");
29        $id = $db->lastInsertId();
30        echo "Last insert id is " . $id . "\n";
31    } catch (PDOException $e) {
32        echo $e->getMessage()."\n";
33    }
34}
35
36testLastInsertId($db);
37unset($db);
38echo "\n";
39?>
40--CLEAN--
41<?php
42require_once __DIR__ . '/inc/mysql_pdo_test.inc';
43$db = MySQLPDOTest::factory();
44$db->exec('DROP TABLE IF EXISTS test_80908');
45?>
46--EXPECT--
47Running test lastInsertId
48Last insert id is 10376293541461622799
49