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--
66[005]
67array(2) {
68  [%u|b%"id"]=>
69  %unicode|string%(1) "1"
70  [%u|b%"label"]=>
71  %unicode|string%(1) "a"
72}
73[006]
74bool(false)
75[008]
76array(5) {
77  [%u|b%"a"]=>
78  %unicode|string%(1) "2"
79  [%u|b%"c"]=>
80  %unicode|string%(1) "3"
81  [%u|b%"C"]=>
82  %unicode|string%(1) "4"
83  [%u|b%"d"]=>
84  NULL
85  [%u|b%"e"]=>
86  %unicode|string%(1) "1"
87}
88
89Warning: mysql_fetch_assoc(): %d is not a valid MySQL result resource in %s on line %d
90[010]
91array(5) {
92  [%u|b%"id"]=>
93  %unicode|string%(1) "1"
94  [%u|b%"label"]=>
95  %unicode|string%(1) "a"
96  [%u|b%"_id"]=>
97  %unicode|string%(1) "1"
98  [%u|b%"_label"]=>
99  %unicode|string%(2) "aa"
100  [%u|b%"_foo"]=>
101  NULL
102}
103done!
104