mysqli_autocommit_oo.phpt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. --TEST--
  2. mysqli->autocommit()
  3. --EXTENSIONS--
  4. mysqli
  5. --SKIPIF--
  6. <?php
  7. require_once('skipifconnectfailure.inc');
  8. require_once('connect.inc');
  9. if (!$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) {
  10. printf("skip Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  11. $host, $user, $db, $port, $socket);
  12. exit(1);
  13. }
  14. if (!have_innodb($link))
  15. die(sprintf("skip Needs InnoDB support, [%d] %s", $link->errno, $link->error));
  16. ?>
  17. --FILE--
  18. <?php
  19. require_once("connect.inc");
  20. if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) {
  21. printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  22. $host, $user, $db, $port, $socket);
  23. }
  24. if (!is_bool($tmp = $mysqli->autocommit(true)))
  25. printf("[002] Expecting boolean/any, got %s/%s\n", gettype($tmp), $tmp);
  26. if (!$mysqli->query('SET AUTOCOMMIT = 0'))
  27. printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error);
  28. if (!$res = $mysqli->query('SELECT @@autocommit as auto_commit'))
  29. printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error);
  30. $tmp = $res->fetch_assoc();
  31. $res->free_result();
  32. if ($tmp['auto_commit'])
  33. printf("[005] Cannot turn off autocommit\n");
  34. if (true !== ($tmp = $mysqli->autocommit( true)))
  35. printf("[006] Expecting true, got %s/%s\n", gettype($tmp), $tmp);
  36. if (!$res = $mysqli->query('SELECT @@autocommit as auto_commit'))
  37. printf("[007] [%d] %s\n", $mysqli->errno, $mysqli->error);
  38. $tmp = $res->fetch_assoc();
  39. $res->free_result();
  40. if (!$tmp['auto_commit'])
  41. printf("[008] Cannot turn on autocommit\n");
  42. if (!$mysqli->query('DROP TABLE IF EXISTS test'))
  43. printf("[009] [%d] %s\n", $mysqli->errno, $mysqli->error);
  44. if (!$mysqli->query('CREATE TABLE test(id INT) ENGINE = InnoDB')) {
  45. printf("[010] Cannot create test table, [%d] %s\n", $mysqli->errno, $mysqli->error);
  46. }
  47. if (!$mysqli->query('INSERT INTO test(id) VALUES (1)'))
  48. printf("[011] [%d] %s\n", $mysqli->errno, $mysqli->error);
  49. if (!$mysqli->query('ROLLBACK'))
  50. printf("[012] [%d] %s\n", $mysqli->errno, $mysqli->error);
  51. if (!$res = $mysqli->query('SELECT COUNT(*) AS num FROM test'))
  52. printf("[013] [%d] %s\n", $mysqli->errno, $mysqli->error);
  53. if ((!$tmp = $res->fetch_assoc()) || (1 != $tmp['num']))
  54. printf("[014] Expecting 1 row in table test, found %d rows. [%d] %s\n",
  55. $tmp['num'], $mysqli->errno, $mysqli->error);
  56. $res->free_result();
  57. if (!$mysqli->query('DROP TABLE IF EXISTS test'))
  58. printf("[015] [%d] %s\n", $mysqli->errno, $mysqli->error);
  59. if (!$mysqli->query('SET AUTOCOMMIT = 1'))
  60. printf("[016] [%d] %s\n", $mysqli->errno, $mysqli->error);
  61. if (!$res = $mysqli->query('SELECT @@autocommit as auto_commit'))
  62. printf("[017] [%d] %s\n", $mysqli->errno, $mysqli->error);
  63. $tmp = $res->fetch_assoc();
  64. $res->free_result();
  65. if (!$tmp['auto_commit'])
  66. printf("[018] Cannot turn on autocommit\n");
  67. if (true !== ($tmp = $mysqli->autocommit( false)))
  68. printf("[019] Expecting true, got %s/%s\n", gettype($tmp), $tmp);
  69. if (!$mysqli->query('CREATE TABLE test(id INT) ENGINE = InnoDB')) {
  70. printf("[020] Cannot create test table, [%d] %s\n", $mysqli->errno, $mysqli->error);
  71. }
  72. if (!$mysqli->query('INSERT INTO test(id) VALUES (1)'))
  73. printf("[021] [%d] %s\n", $mysqli->errno, $mysqli->error);
  74. if (!$mysqli->query('ROLLBACK'))
  75. printf("[022] [%d] %s\n", $mysqli->errno, $mysqli->error);
  76. if (!$res = $mysqli->query('SELECT COUNT(*) AS num FROM test'))
  77. printf("[023] [%d] %s\n", $mysqli->errno, $mysqli->error);
  78. $tmp = $res->fetch_assoc();
  79. if (0 != $tmp['num'])
  80. printf("[24] Expecting 0 rows in table test, found %d rows\n", $tmp['num']);
  81. $res->free_result();
  82. if (!$mysqli->query('INSERT INTO test(id) VALUES (1)'))
  83. printf("[025] [%d] %s\n", $mysqli->errno, $mysqli->error);
  84. if (!$mysqli->query('COMMIT'))
  85. printf("[025] [%d] %s\n", $mysqli->errno, $mysqli->error);
  86. if (!$res = $mysqli->query('SELECT COUNT(*) AS num FROM test'))
  87. printf("[027] [%d] %s\n", $mysqli->errno, $mysqli->error);
  88. if ((!$tmp = $res->fetch_assoc()) || (1 != $tmp['num']))
  89. printf("[028] Expecting 1 row in table test, found %d rows. [%d] %s\n",
  90. $tmp['num'], $mysqli->errno, $mysqli->error);
  91. $res->free_result();
  92. if (!$mysqli->query('DROP TABLE IF EXISTS test'))
  93. printf("[029] [%d] %s\n", $mysqli->errno, $mysqli->error);
  94. $mysqli->close();
  95. try {
  96. $mysqli->autocommit(false);
  97. } catch (Error $exception) {
  98. echo $exception->getMessage() . "\n";
  99. }
  100. print "done!";
  101. ?>
  102. --CLEAN--
  103. <?php
  104. require_once("clean_table.inc");
  105. ?>
  106. --EXPECT--
  107. my_mysqli object is already closed
  108. done!