1--TEST--
2mysql_fetch_assoc()
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10include "connect.inc";
11
12$tmp    = NULL;
13$link   = NULL;
14
15// Note: no SQL type tests, internally the same function gets used as for mysql_fetch_array() which does a lot of SQL type test
16
17if (!is_null($tmp = @mysql_fetch_assoc()))
18	printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
19
20if (NULL !== ($tmp = @mysql_fetch_assoc($link)))
21	printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
22
23require('table.inc');
24if (!$res = mysql_query("SELECT id, label FROM test ORDER BY id LIMIT 1", $link)) {
25	printf("[004] [%d] %s\n", mysql_errno($link), mysql_error($link));
26}
27
28print "[005]\n";
29var_dump(mysql_fetch_assoc($res));
30
31print "[006]\n";
32var_dump(mysql_fetch_assoc($res));
33
34mysql_free_result($res);
35
36if (!$res = mysql_query("SELECT 1 AS a, 2 AS a, 3 AS c, 4 AS C, NULL AS d, true AS e", $link)) {
37	printf("[007] Cannot run query, [%d] %s\n", mysql_errno($link), $mysql_error($link));
38}
39print "[008]\n";
40var_dump(mysql_fetch_assoc($res));
41
42mysql_free_result($res);
43
44if (false !== ($tmp = mysql_fetch_assoc($res)))
45	printf("[008] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
46
47mysql_close($link);
48
49include('table.inc');
50if (!$res = mysql_query("SELECT id, label, id AS _id, CONCAT(label, 'a') _label, NULL as _foo FROM test _test ORDER BY id ASC LIMIT 1", $link)) {
51	printf("[009] [%d] %s\n", mysql_errno($link), $mysql_error($link));
52}
53print "[010]\n";
54var_dump(mysql_fetch_assoc($res));
55mysql_free_result($res);
56
57mysql_close($link);
58
59print "done!";
60?>
61--CLEAN--
62<?php
63require_once("clean_table.inc");
64?>
65--EXPECTF--
66Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
67[005]
68array(2) {
69  [%u|b%"id"]=>
70  %unicode|string%(1) "1"
71  [%u|b%"label"]=>
72  %unicode|string%(1) "a"
73}
74[006]
75bool(false)
76[008]
77array(5) {
78  [%u|b%"a"]=>
79  %unicode|string%(1) "2"
80  [%u|b%"c"]=>
81  %unicode|string%(1) "3"
82  [%u|b%"C"]=>
83  %unicode|string%(1) "4"
84  [%u|b%"d"]=>
85  NULL
86  [%u|b%"e"]=>
87  %unicode|string%(1) "1"
88}
89
90Warning: mysql_fetch_assoc(): %d is not a valid MySQL result resource in %s on line %d
91
92Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
93[010]
94array(5) {
95  [%u|b%"id"]=>
96  %unicode|string%(1) "1"
97  [%u|b%"label"]=>
98  %unicode|string%(1) "a"
99  [%u|b%"_id"]=>
100  %unicode|string%(1) "1"
101  [%u|b%"_label"]=>
102  %unicode|string%(2) "aa"
103  [%u|b%"_foo"]=>
104  NULL
105}
106done!
107