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