mysqli_commit_oo.phpt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. --TEST--
  2. mysqli_commit()
  3. --EXTENSIONS--
  4. mysqli
  5. --SKIPIF--
  6. <?php
  7. require_once('skipifconnectfailure.inc');
  8. require_once('connect.inc');
  9. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  10. die(sprintf("skip Cannot connect, [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));
  11. if (!have_innodb($link))
  12. die(sprintf("skip Needs InnoDB support, [%d] %s", $link->errno, $link->error));
  13. ?>
  14. --FILE--
  15. <?php
  16. require_once("connect.inc");
  17. $tmp = NULL;
  18. $link = NULL;
  19. $mysqli = new mysqli();
  20. try {
  21. $mysqli->commit();
  22. } catch (Error $exception) {
  23. echo $exception->getMessage() . "\n";
  24. }
  25. if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) {
  26. printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  27. $host, $user, $db, $port, $socket);
  28. }
  29. if (true !== ($tmp = $mysqli->commit())) {
  30. printf("[002] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);
  31. }
  32. if (true !== ($tmp = $mysqli->autocommit(false))) {
  33. printf("[003] Cannot turn off autocommit, expecting true, got %s/%s\n", gettype($tmp), $tmp);
  34. }
  35. if (!$mysqli->query('DROP TABLE IF EXISTS test')) {
  36. printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error);
  37. }
  38. if (!$mysqli->query('CREATE TABLE test(id INT) ENGINE = InnoDB')) {
  39. printf("[005] Cannot create test table, [%d] %s\n", $mysqli->errno, $mysqli->error);
  40. }
  41. if (!$mysqli->query('INSERT INTO test(id) VALUES (1)')) {
  42. printf("[006] [%d] %s\n", $mysqli->errno, $mysqli->error);
  43. }
  44. $tmp = $mysqli->commit();
  45. if ($tmp !== true) {
  46. printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  47. }
  48. if (!$mysqli->query('ROLLBACK'))
  49. printf("[008] [%d] %s\n", $mysqli->errno, $mysqli->error);
  50. if (!$res = $mysqli->query('SELECT COUNT(*) AS num FROM test')) {
  51. printf("[009] [%d] %s\n", $mysqli->errno, $mysqli->error);
  52. }
  53. $tmp = $res->fetch_assoc();
  54. if (1 != $tmp['num']) {
  55. printf("[010] Expecting 1 row in table test, found %d rows\n", $tmp['num']);
  56. }
  57. $res->free();
  58. if (!$mysqli->query('DROP TABLE IF EXISTS test')) {
  59. printf("[011] [%d] %s\n", $mysqli->errno, $mysqli->error);
  60. }
  61. if (!$mysqli->commit(0 , "tx_name0123")) {
  62. printf("[012] [%d] %s\n", $mysqli->errno, $mysqli->error);
  63. }
  64. var_dump($mysqli->commit(0 , "*/ nonsense"));
  65. var_dump($mysqli->commit(0 , "tx_name ulf вендел"));
  66. var_dump($mysqli->commit(0 , "tx_name \t\n\r\b"));
  67. if (!$mysqli->commit(MYSQLI_TRANS_COR_AND_CHAIN | MYSQLI_TRANS_COR_NO_RELEASE , "tx_name")) {
  68. printf("[016] [%d] %s\n", $mysqli->errno, $mysqli->error);
  69. }
  70. $mysqli->close();
  71. try {
  72. $mysqli->commit();
  73. } catch (Error $exception) {
  74. echo $exception->getMessage() . "\n";
  75. }
  76. print "done!";
  77. --CLEAN--
  78. <?php
  79. require_once("clean_table.inc");
  80. ?>
  81. --EXPECTF--
  82. mysqli object is not fully initialized
  83. Warning: mysqli::commit(): Transaction name has been truncated, since it can only contain the A-Z, a-z, 0-9, "\", "-", "_", and "=" characters in %s on line %d
  84. bool(true)
  85. Warning: mysqli::commit(): Transaction name has been truncated, since it can only contain the A-Z, a-z, 0-9, "\", "-", "_", and "=" characters in %s on line %d
  86. bool(true)
  87. Warning: mysqli::commit(): Transaction name has been truncated, since it can only contain the A-Z, a-z, 0-9, "\", "-", "_", and "=" characters in %s on line %d
  88. bool(true)
  89. my_mysqli object is already closed
  90. done!