mysqli_stmt_fetch.phpt 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. --TEST--
  2. mysqli_stmt_fetch()
  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. /*
  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. $tmp = NULL;
  18. $link = NULL;
  19. if (!is_null($tmp = @mysqli_stmt_fetch()))
  20. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  21. if (!is_null($tmp = @mysqli_stmt_fetch($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. // stmt object status test
  27. if (NULL !== ($tmp = mysqli_stmt_fetch($stmt)))
  28. printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  29. if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2"))
  30. printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  31. // FIXME - different versions return different values ?!
  32. if ((NULL !== ($tmp = mysqli_stmt_fetch($stmt))) && (false !== $tmp))
  33. printf("[006] Expecting NULL or boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  34. if (!mysqli_stmt_execute($stmt))
  35. printf("[007] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  36. if (true !== ($tmp = mysqli_stmt_fetch($stmt)))
  37. printf("[008] NULL, got %s/%s\n", gettype($tmp), $tmp);
  38. mysqli_stmt_close($stmt);
  39. if (!$stmt = mysqli_stmt_init($link))
  40. printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  41. if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2"))
  42. printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  43. if (!mysqli_stmt_execute($stmt))
  44. printf("[011] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  45. $id = NULL;
  46. $label = NULL;
  47. if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id, $label)))
  48. printf("[012] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  49. if (true !== ($tmp = mysqli_stmt_fetch($stmt)))
  50. printf("[013] Expecting boolean/true, got %s/%s, [%d] %s\n",
  51. gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
  52. if (!mysqli_kill($link, mysqli_thread_id($link)))
  53. printf("[014] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  54. if (true !== ($tmp = mysqli_stmt_fetch($stmt)))
  55. printf("[015] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  56. mysqli_stmt_close($stmt);
  57. if (NULL !== ($tmp = mysqli_stmt_fetch($stmt)))
  58. printf("[016] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  59. mysqli_close($link);
  60. /* Check that the function alias exists. It's a deprecated function,
  61. but we have not announce the removal so far, therefore we need to check for it */
  62. if (!is_null($tmp = @mysqli_stmt_fetch()))
  63. printf("[017] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  64. print "done!";
  65. ?>
  66. --CLEAN--
  67. <?php
  68. require_once("clean_table.inc");
  69. ?>
  70. --EXPECTF--
  71. Warning: mysqli_stmt_fetch(): invalid object or resource mysqli_stmt
  72. in %s on line %d
  73. [014] [%d] Commands out of sync; you can't run this command now
  74. Warning: mysqli_stmt_fetch(): Couldn't fetch mysqli_stmt in %s on line %d
  75. done!