1--TEST--
2mysqli_fetch_assoc()
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10    require('table.inc');
11
12    if (!$res = mysqli_query($link, "SELECT 1, 2")) {
13        printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
14    }
15    print "[002]\n";
16    var_dump(mysqli_fetch_assoc($res));
17    mysqli_free_result($res);
18
19    if (!$res = mysqli_query($link, "SELECT 1 AS a, 2")) {
20        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
21    }
22    print "[004]\n";
23    var_dump(mysqli_fetch_assoc($res));
24    mysqli_free_result($res);
25
26    if (!$res = mysqli_query($link, "SELECT 1 AS a, 2, 2 as '2'")) {
27        printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
28    }
29    print "[006]\n";
30    var_dump(mysqli_fetch_assoc($res));
31    mysqli_free_result($res);
32
33    if (!$res = mysqli_query($link, "SELECT 1 AS a, 2 as '2', 2")) {
34        printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
35    }
36    print "[008]\n";
37    var_dump(mysqli_fetch_assoc($res));
38    mysqli_free_result($res);
39
40    /* Now do it with unbuffered queries */
41    if (!$res = mysqli_real_query($link, "SELECT 1, 2")) {
42        printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
43    }
44    if (!$res = mysqli_use_result($link)) {
45        printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
46    }
47    print "[011]\n";
48    var_dump(mysqli_fetch_assoc($res));
49    mysqli_free_result($res);
50
51    if (!$res = mysqli_real_query($link, "SELECT 1 AS a, 2")) {
52        printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
53    }
54    if (!$res = mysqli_use_result($link)) {
55        printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
56    }
57    print "[014]\n";
58    var_dump(mysqli_fetch_assoc($res));
59    mysqli_free_result($res);
60
61    if (!$res = mysqli_real_query($link, "SELECT 1 AS a, 2, 2 as '2'")) {
62        printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
63    }
64    if (!$res = mysqli_use_result($link)) {
65        printf("[016] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
66    }
67    print "[017]\n";
68    var_dump(mysqli_fetch_assoc($res));
69    mysqli_free_result($res);
70
71    if (!$res = mysqli_real_query($link, "SELECT 1 AS a, 2 as '2', 2")) {
72        printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
73    }
74    if (!$res = mysqli_use_result($link)) {
75        printf("[016] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
76    }
77    print "[017]\n";
78    var_dump(mysqli_fetch_assoc($res));
79    mysqli_free_result($res);
80    mysqli_close($link);
81
82    print "done!";
83?>
84--EXPECTF--
85[002]
86array(2) {
87  [1]=>
88  string(1) "1"
89  [2]=>
90  string(1) "2"
91}
92[004]
93array(2) {
94  ["a"]=>
95  string(1) "1"
96  [2]=>
97  string(1) "2"
98}
99[006]
100array(2) {
101  ["a"]=>
102  string(1) "1"
103  [2]=>
104  string(1) "2"
105}
106[008]
107array(2) {
108  ["a"]=>
109  string(1) "1"
110  [2]=>
111  string(1) "2"
112}
113[011]
114array(2) {
115  [1]=>
116  string(1) "1"
117  [2]=>
118  string(1) "2"
119}
120[014]
121array(2) {
122  ["a"]=>
123  %s(1) "1"
124  [2]=>
125  %s(1) "2"
126}
127[017]
128array(2) {
129  ["a"]=>
130  string(1) "1"
131  [2]=>
132  string(1) "2"
133}
134[017]
135array(2) {
136  ["a"]=>
137  string(1) "1"
138  [2]=>
139  string(1) "2"
140}
141done!
142