mysqli_stmt_fetch.phpt 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. --TEST--
  2. mysqli_stmt_fetch()
  3. --EXTENSIONS--
  4. mysqli
  5. --SKIPIF--
  6. <?php
  7. require_once('skipifconnectfailure.inc');
  8. ?>
  9. --FILE--
  10. <?php
  11. /*
  12. NOTE: no datatype tests here! This is done by
  13. mysqli_stmt_bind_result.phpt already. Restrict
  14. this test case to the basics.
  15. */
  16. require_once("connect.inc");
  17. require('table.inc');
  18. if (!$stmt = mysqli_stmt_init($link))
  19. printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  20. // stmt object status test
  21. try {
  22. mysqli_stmt_fetch($stmt);
  23. } catch (Error $exception) {
  24. echo $exception->getMessage() . "\n";
  25. }
  26. if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2"))
  27. printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  28. // FIXME - different versions return different values ?!
  29. if ((NULL !== ($tmp = mysqli_stmt_fetch($stmt))) && (false !== $tmp))
  30. printf("[006] Expecting NULL or boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  31. if (!mysqli_stmt_execute($stmt))
  32. printf("[007] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  33. if (true !== ($tmp = mysqli_stmt_fetch($stmt)))
  34. printf("[008] NULL, got %s/%s\n", gettype($tmp), $tmp);
  35. mysqli_stmt_close($stmt);
  36. if (!$stmt = mysqli_stmt_init($link))
  37. printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  38. if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2"))
  39. printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  40. if (!mysqli_stmt_execute($stmt))
  41. printf("[011] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  42. $id = NULL;
  43. $label = NULL;
  44. if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id, $label)))
  45. printf("[012] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  46. if (true !== ($tmp = mysqli_stmt_fetch($stmt)))
  47. printf("[013] Expecting boolean/true, got %s/%s, [%d] %s\n",
  48. gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  49. if (!mysqli_kill($link, mysqli_thread_id($link)))
  50. printf("[014] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  51. if (true !== ($tmp = mysqli_stmt_fetch($stmt)))
  52. printf("[015] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  53. mysqli_stmt_close($stmt);
  54. try {
  55. mysqli_stmt_fetch($stmt);
  56. } catch (Error $exception) {
  57. echo $exception->getMessage() . "\n";
  58. }
  59. mysqli_close($link);
  60. print "done!";
  61. ?>
  62. --CLEAN--
  63. <?php
  64. require_once("clean_table.inc");
  65. ?>
  66. --EXPECTF--
  67. mysqli_stmt object is not fully initialized
  68. [014] [%d] Commands out of sync; you can't run this command now
  69. mysqli_stmt object is already closed
  70. done!