mysqli_fetch_assoc.phpt 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. if (!is_null($tmp = @mysqli_fetch_assoc()))
  16. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  17. if (!is_null($tmp = @mysqli_fetch_assoc($link)))
  18. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  19. require('table.inc');
  20. if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id LIMIT 1")) {
  21. printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  22. }
  23. print "[005]\n";
  24. var_dump(mysqli_fetch_assoc($res));
  25. print "[006]\n";
  26. var_dump(mysqli_fetch_assoc($res));
  27. mysqli_free_result($res);
  28. if (!$res = mysqli_query($link, "SELECT
  29. 1 AS a,
  30. 2 AS a,
  31. 3 AS c,
  32. 4 AS C,
  33. NULL AS d,
  34. true AS e,
  35. 5 AS '-1',
  36. 6 AS '-10',
  37. 7 AS '-100',
  38. 8 AS '-1000',
  39. 9 AS '10000',
  40. 'a' AS '100000',
  41. 'b' AS '1000000',
  42. 'c' AS '9',
  43. 'd' AS '9',
  44. 'e' AS '01',
  45. 'f' AS '-02'
  46. ")) {
  47. printf("[007] Cannot run query, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  48. }
  49. print "[008]\n";
  50. var_dump(mysqli_fetch_assoc($res));
  51. mysqli_free_result($res);
  52. if (NULL !== ($tmp = mysqli_fetch_assoc($res)))
  53. printf("[008] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  54. mysqli_close($link);
  55. print "done!";
  56. ?>
  57. --CLEAN--
  58. <?php
  59. require_once("clean_table.inc");
  60. ?>
  61. --EXPECTF--
  62. [005]
  63. array(2) {
  64. [%u|b%"id"]=>
  65. %unicode|string%(1) "1"
  66. [%u|b%"label"]=>
  67. %unicode|string%(1) "a"
  68. }
  69. [006]
  70. NULL
  71. [008]
  72. array(15) {
  73. [%u|b%"a"]=>
  74. %unicode|string%(1) "2"
  75. [%u|b%"c"]=>
  76. %unicode|string%(1) "3"
  77. [%u|b%"C"]=>
  78. %unicode|string%(1) "4"
  79. [%u|b%"d"]=>
  80. NULL
  81. [%u|b%"e"]=>
  82. %unicode|string%(1) "1"
  83. [-1]=>
  84. %unicode|string%(1) "5"
  85. [-10]=>
  86. %unicode|string%(1) "6"
  87. [-100]=>
  88. %unicode|string%(1) "7"
  89. [-1000]=>
  90. %unicode|string%(1) "8"
  91. [10000]=>
  92. %unicode|string%(1) "9"
  93. [100000]=>
  94. %unicode|string%(1) "a"
  95. [1000000]=>
  96. %unicode|string%(1) "b"
  97. [9]=>
  98. %unicode|string%(1) "d"
  99. [%u|b%"01"]=>
  100. %unicode|string%(1) "e"
  101. [%u|b%"-02"]=>
  102. %unicode|string%(1) "f"
  103. }
  104. Warning: mysqli_fetch_assoc(): Couldn't fetch mysqli_result in %s on line %d
  105. done!