mysqli_stmt_close.phpt 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. --TEST--
  2. mysqli_stmt_close()
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifemb.inc');
  7. require_once('skipifconnectfailure.inc');
  8. ?>
  9. --FILE--
  10. <?php
  11. require_once("connect.inc");
  12. $tmp = NULL;
  13. $link = NULL;
  14. if (!is_null($tmp = @mysqli_stmt_close()))
  15. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  16. if (!is_null($tmp = @mysqli_stmt_close($link)))
  17. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  18. require('table.inc');
  19. if (!$stmt = mysqli_stmt_init($link))
  20. printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  21. // Yes, amazing, eh? AFAIK a work around of a constructor bug...
  22. if (!is_null($tmp = mysqli_stmt_close($stmt)))
  23. printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  24. if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test"))
  25. printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  26. if (true !== ($tmp = mysqli_stmt_close($stmt)))
  27. printf("[006] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  28. if (!is_null($tmp = mysqli_stmt_close($stmt)))
  29. printf("[007] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  30. if (!$stmt = mysqli_stmt_init($link))
  31. printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  32. if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (?, ?)"))
  33. printf("[009] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  34. $id = $label = null;
  35. if (!mysqli_stmt_bind_param($stmt, "is", $id, $label))
  36. printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  37. $id = 100; $label = 'z';
  38. if (!mysqli_stmt_execute($stmt))
  39. printf("[011] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  40. mysqli_kill($link, mysqli_thread_id($link));
  41. if (true !== ($tmp = mysqli_stmt_close($stmt)))
  42. printf("[012] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  43. mysqli_close($link);
  44. require('table.inc');
  45. if (!$stmt = mysqli_stmt_init($link))
  46. printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  47. if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test"))
  48. printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  49. $id = $label = null;
  50. if (!mysqli_stmt_bind_result($stmt, $id, $label))
  51. printf("[015] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  52. if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_fetch($stmt))
  53. printf("[016] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  54. mysqli_kill($link, mysqli_thread_id($link));
  55. if (true !== ($tmp = mysqli_stmt_close($stmt)))
  56. printf("[017] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  57. print "done!";
  58. ?>
  59. --CLEAN--
  60. <?php
  61. require_once("clean_table.inc");
  62. ?>
  63. --EXPECTF--
  64. Warning: mysqli_stmt_close(): invalid object or resource mysqli_stmt
  65. in %s on line %d
  66. Warning: mysqli_stmt_close(): Couldn't fetch mysqli_stmt in %s on line %d
  67. done!