mysqli_stmt_reset.phpt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. --TEST--
  2. mysqli_stmt_reset()
  3. --EXTENSIONS--
  4. mysqli
  5. --SKIPIF--
  6. <?php
  7. require_once('skipifconnectfailure.inc');
  8. ?>
  9. --FILE--
  10. <?php
  11. require_once("connect.inc");
  12. // Note: No SQL tests here! We can expand one of the *fetch()
  13. // tests to a generic SQL test, if we ever need that.
  14. // We would duplicate the SQL test cases if we have it here and in one of the
  15. // fetch tests, because the fetch tests would have to call prepare/execute etc.
  16. // anyway.
  17. require('table.inc');
  18. if (!$stmt = mysqli_stmt_init($link))
  19. printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  20. try {
  21. mysqli_stmt_reset($stmt);
  22. } catch (Error $exception) {
  23. echo $exception->getMessage() . "\n";
  24. }
  25. if (true !== ($tmp = mysqli_stmt_prepare($stmt, 'SELECT id FROM test')))
  26. printf("[005] Expecting boolean/true, got %s/%s, [%d] %s\n",
  27. gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  28. if (true !== ($tmp = mysqli_stmt_reset($stmt)))
  29. printf("[006] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  30. if (true !== ($tmp = mysqli_stmt_execute($stmt)))
  31. printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  32. $id = null;
  33. if (!mysqli_stmt_bind_result($stmt, $id))
  34. printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  35. if (!mysqli_stmt_fetch($stmt))
  36. printf("[009] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  37. var_dump($id);
  38. mysqli_stmt_close($stmt);
  39. if (!$stmt = mysqli_stmt_init($link))
  40. printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  41. if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
  42. printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  43. if (!mysqli_query($link, "CREATE TABLE test(id INT NOT NULL AUTO_INCREMENT, label BLOB, PRIMARY KEY(id))"))
  44. printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  45. if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(label) VALUES (?)"))
  46. printf("[013] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  47. $label = null;
  48. if (!mysqli_stmt_bind_param($stmt, "b", $label))
  49. printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  50. $label = 'abc';
  51. for ($i = 0; $i < 10; $i++) {
  52. if (!mysqli_stmt_send_long_data($stmt, 0, $label))
  53. printf("[015 - %d] [%d] %s\n", $i, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  54. }
  55. if (!mysqli_stmt_reset($stmt))
  56. printf("[016] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  57. if (!mysqli_stmt_execute($stmt))
  58. printf("[017] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  59. if (!$res = mysqli_query($link, "SELECT label FROM test"))
  60. printf("[018] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  61. if (!$row = mysqli_fetch_assoc($res))
  62. printf("[019] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  63. mysqli_free_result($res);
  64. if ($row['label'] != '')
  65. printf("[020] Expecting empty string, got string/%s\n", $row['label']);
  66. mysqli_stmt_close($stmt);
  67. try {
  68. mysqli_stmt_reset($stmt);
  69. } catch (Error $exception) {
  70. echo $exception->getMessage() . "\n";
  71. }
  72. mysqli_close($link);
  73. print "done!";
  74. ?>
  75. --CLEAN--
  76. <?php
  77. require_once("clean_table.inc");
  78. ?>
  79. --EXPECT--
  80. mysqli_stmt object is not fully initialized
  81. int(1)
  82. mysqli_stmt object is already closed
  83. done!