bug80908.phpt 1.3 KB

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