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