mysqli_fetch_assoc_oo.phpt 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. --TEST--
  2. mysqli_fetch_assoc()
  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. // Note: no SQL type tests, internally the same function gets used as for mysqli_fetch_array() which does a lot of SQL type test
  15. $mysqli = new mysqli();
  16. $res = @new mysqli_result($mysqli);
  17. if (!is_null($tmp = @$res->fetch_assoc()))
  18. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  19. require('table.inc');
  20. if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
  21. printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  22. $host, $user, $db, $port, $socket);
  23. if (!is_null($tmp = @$res->fetch_assoc($link)))
  24. printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  25. if (!$res = $mysqli->query("SELECT id, label FROM test ORDER BY id LIMIT 1")) {
  26. printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error);
  27. }
  28. print "[005]\n";
  29. var_dump($res->fetch_assoc());
  30. print "[006]\n";
  31. var_dump($res->fetch_assoc());
  32. $res->free_result();
  33. if (!$res = $mysqli->query("SELECT 1 AS a, 2 AS a, 3 AS c, 4 AS C, NULL AS d, true AS e")) {
  34. printf("[007] Cannot run query, [%d] %s\n", $mysqli->errno, $mysqli->error);
  35. }
  36. print "[008]\n";
  37. var_dump($res->fetch_assoc());
  38. $res->free_result();
  39. if (NULL !== ($tmp = $res->fetch_assoc()))
  40. printf("[008] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  41. mysqli_close($link);
  42. print "done!";
  43. ?>
  44. --CLEAN--
  45. <?php
  46. require_once("clean_table.inc");
  47. ?>
  48. --EXPECTF--
  49. [005]
  50. array(2) {
  51. [%u|b%"id"]=>
  52. %unicode|string%(1) "1"
  53. [%u|b%"label"]=>
  54. %unicode|string%(1) "a"
  55. }
  56. [006]
  57. NULL
  58. [008]
  59. array(5) {
  60. [%u|b%"a"]=>
  61. %unicode|string%(1) "2"
  62. [%u|b%"c"]=>
  63. %unicode|string%(1) "3"
  64. [%u|b%"C"]=>
  65. %unicode|string%(1) "4"
  66. [%u|b%"d"]=>
  67. NULL
  68. [%u|b%"e"]=>
  69. %unicode|string%(1) "1"
  70. }
  71. Warning: mysqli_result::fetch_assoc(): Couldn't fetch mysqli_result in %s on line %d
  72. done!