mysqli_savepoint.phpt 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. --TEST--
  2. mysqli_savepoint()
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifemb.inc');
  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("Cannot connect, [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));
  11. if (!have_innodb($link))
  12. die(sprintf("Needs InnoDB support, [%d] %s", $link->errno, $link->error));
  13. ?>
  14. --FILE--
  15. <?php
  16. require_once("connect.inc");
  17. /* {{{ proto bool mysqli_savepoint(object link, string name) */
  18. $tmp = NULL;
  19. $link = NULL;
  20. if (!is_null($tmp = @mysqli_savepoint()))
  21. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  22. if (!is_null($tmp = @mysqli_savepoint($link)))
  23. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  24. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  25. printf("[003] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  26. $host, $user, $db, $port, $socket);
  27. $name = array();
  28. if (!is_null($tmp = @mysqli_savepoint($link, $name)))
  29. printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  30. if (!is_null($tmp = @mysqli_savepoint($link, 'foo', $link)))
  31. printf("[005] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  32. if (false !== ($tmp = mysqli_savepoint($link, '')))
  33. printf("[006] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
  34. if (!mysqli_query($link, 'DROP TABLE IF EXISTS test'))
  35. printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  36. if (!mysqli_query($link, 'CREATE TABLE test(id INT) ENGINE = InnoDB'))
  37. printf("[008] Cannot create test table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  38. if (true !== ($tmp = mysqli_autocommit($link, false)))
  39. printf("[009] Cannot turn off autocommit, expecting true, got %s/%s\n", gettype($tmp), $tmp);
  40. /* overrule autocommit */
  41. if (true !== ($tmp = mysqli_savepoint($link, 'my')))
  42. printf("[010] Got %s - [%d] %s\n", var_dump($tmp, true), mysqli_errno($link), mysqli_error($link));
  43. if (!mysqli_query($link, 'INSERT INTO test(id) VALUES (1)'))
  44. printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  45. $tmp = mysqli_rollback($link);
  46. if ($tmp !== true)
  47. printf("[012] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  48. print "done!";
  49. ?>
  50. --CLEAN--
  51. <?php
  52. require_once("clean_table.inc");
  53. ?>
  54. --EXPECTF--
  55. Warning: mysqli_savepoint(): Savepoint name cannot be empty in %s on line %d
  56. done!