mysqli_rollback.phpt 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. --TEST--
  2. mysqli_rollback()
  3. --SKIPIF--
  4. <?php ?>
  5. <?php ?>
  6. <?PHP
  7. require_once('skipif.inc');
  8. require_once('skipifemb.inc');
  9. require_once('skipifconnectfailure.inc');
  10. require_once('connect.inc');
  11. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  12. die(sprintf("Cannot connect, [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));
  13. if (!have_innodb($link))
  14. die(sprintf("Needs InnoDB support, [%d] %s", $link->errno, $link->error));
  15. ?>
  16. --FILE--
  17. <?php
  18. require_once("connect.inc");
  19. $tmp = NULL;
  20. $link = NULL;
  21. if (!is_null($tmp = @mysqli_rollback()))
  22. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  23. if (!is_null($tmp = @mysqli_rollback($link)))
  24. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  25. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  26. printf("[003] 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. if (!is_null($tmp = @mysqli_rollback($link, 'foo')))
  29. printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  30. if (true !== ($tmp = mysqli_autocommit($link, false)))
  31. printf("[005] Cannot turn off autocommit, expecting true, got %s/%s\n", gettype($tmp), $tmp);
  32. if (!mysqli_query($link, 'DROP TABLE IF EXISTS test'))
  33. printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  34. if (!mysqli_query($link, 'CREATE TABLE test(id INT) ENGINE = InnoDB'))
  35. printf("[007] Cannot create test table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  36. if (!mysqli_query($link, 'INSERT INTO test(id) VALUES (1)'))
  37. printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  38. $tmp = mysqli_rollback($link);
  39. if ($tmp !== true)
  40. printf("[009] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  41. if (!$res = mysqli_query($link, 'SELECT COUNT(*) AS num FROM test'))
  42. printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  43. $tmp = mysqli_fetch_assoc($res);
  44. if (0 != $tmp['num'])
  45. printf("[12] Expecting 0 rows in table test, found %d rows\n", $tmp['num']);
  46. mysqli_free_result($res);
  47. if (!mysqli_query($link, 'DROP TABLE IF EXISTS test'))
  48. printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  49. mysqli_close($link);
  50. if (!is_null($tmp = mysqli_rollback($link)))
  51. printf("[014] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  52. print "done!\n";
  53. ?>
  54. --CLEAN--
  55. <?php
  56. require_once("clean_table.inc");
  57. ?>
  58. --EXPECTF--
  59. Warning: mysqli_rollback(): Couldn't fetch mysqli in %s on line %d
  60. done!