1--TEST-- 2mysqli_fetch_assoc() 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 7require_once('skipifconnectfailure.inc'); 8?> 9--FILE-- 10<?php 11 require_once("connect.inc"); 12 13 // Note: no SQL type tests, internally the same function gets used as for mysqli_fetch_array() which does a lot of SQL type test 14 15 require('table.inc'); 16 if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id LIMIT 1")) { 17 printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 18 } 19 20 print "[005]\n"; 21 var_dump(mysqli_fetch_assoc($res)); 22 23 print "[006]\n"; 24 var_dump(mysqli_fetch_assoc($res)); 25 26 mysqli_free_result($res); 27 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 52 mysqli_free_result($res); 53 54 try { 55 mysqli_fetch_assoc($res); 56 } catch (Error $exception) { 57 echo $exception->getMessage() . "\n"; 58 } 59 60 mysqli_close($link); 61 62 print "done!"; 63?> 64--CLEAN-- 65<?php 66 require_once("clean_table.inc"); 67?> 68--EXPECT-- 69[005] 70array(2) { 71 ["id"]=> 72 string(1) "1" 73 ["label"]=> 74 string(1) "a" 75} 76[006] 77NULL 78[008] 79array(15) { 80 ["a"]=> 81 string(1) "2" 82 ["c"]=> 83 string(1) "3" 84 ["C"]=> 85 string(1) "4" 86 ["d"]=> 87 NULL 88 ["e"]=> 89 string(1) "1" 90 [-1]=> 91 string(1) "5" 92 [-10]=> 93 string(1) "6" 94 [-100]=> 95 string(1) "7" 96 [-1000]=> 97 string(1) "8" 98 [10000]=> 99 string(1) "9" 100 [100000]=> 101 string(1) "a" 102 [1000000]=> 103 string(1) "b" 104 [9]=> 105 string(1) "d" 106 ["01"]=> 107 string(1) "e" 108 ["-02"]=> 109 string(1) "f" 110} 111mysqli_result object is already closed 112done! 113