mysqli_stmt_reset.phpt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. --TEST--
  2. mysqli_stmt_reset()
  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. // 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. $tmp = NULL;
  18. $link = NULL;
  19. if (!is_null($tmp = @mysqli_stmt_reset()))
  20. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  21. if (!is_null($tmp = @mysqli_stmt_reset($link)))
  22. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  23. require('table.inc');
  24. if (!$stmt = mysqli_stmt_init($link))
  25. printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  26. if (NULL !== ($tmp = mysqli_stmt_reset($stmt)))
  27. printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  28. if (true !== ($tmp = mysqli_stmt_prepare($stmt, 'SELECT id FROM test')))
  29. printf("[005] Expecting boolean/true, got %s/%s, [%d] %s\n",
  30. gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  31. if (true !== ($tmp = mysqli_stmt_reset($stmt)))
  32. printf("[006] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  33. if (true !== ($tmp = mysqli_stmt_execute($stmt)))
  34. printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  35. $id = null;
  36. if (!mysqli_stmt_bind_result($stmt, $id))
  37. printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  38. if (!mysqli_stmt_fetch($stmt))
  39. printf("[009] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  40. var_dump($id);
  41. mysqli_stmt_close($stmt);
  42. if (!$stmt = mysqli_stmt_init($link))
  43. printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  44. if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
  45. printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  46. if (!mysqli_query($link, "CREATE TABLE test(id INT NOT NULL AUTO_INCREMENT, label BLOB, PRIMARY KEY(id))"))
  47. printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  48. if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(label) VALUES (?)"))
  49. printf("[013] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  50. $label = null;
  51. if (!mysqli_stmt_bind_param($stmt, "b", $label))
  52. printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  53. $label = 'abc';
  54. for ($i = 0; $i < 10; $i++) {
  55. if (!mysqli_stmt_send_long_data($stmt, 0, $label))
  56. printf("[015 - %d] [%d] %s\n", $i, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  57. }
  58. if (!mysqli_stmt_reset($stmt))
  59. printf("[016] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  60. if (!mysqli_stmt_execute($stmt))
  61. printf("[017] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  62. if (!$res = mysqli_query($link, "SELECT label FROM test"))
  63. printf("[018] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  64. if (!$row = mysqli_fetch_assoc($res))
  65. printf("[019] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  66. mysqli_free_result($res);
  67. if ($row['label'] != '')
  68. printf("[020] Expecting empty string, got string/%s\n", $row['label']);
  69. mysqli_stmt_close($stmt);
  70. if (NULL !== ($tmp = mysqli_stmt_reset($stmt)))
  71. printf("[021] Expecting NULL, got %s/%s\n");
  72. mysqli_close($link);
  73. print "done!";
  74. ?>
  75. --CLEAN--
  76. <?php
  77. require_once("clean_table.inc");
  78. ?>
  79. --EXPECTF--
  80. Warning: mysqli_stmt_reset(): invalid object or resource mysqli_stmt
  81. in %s on line %d
  82. int(1)
  83. Warning: mysqli_stmt_reset(): Couldn't fetch mysqli_stmt in %s on line %d
  84. done!