Annotation of embedaddon/php/ext/mysql/tests/mysql_fetch_assoc.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: mysql_fetch_assoc()
3: --SKIPIF--
4: <?php
5: require_once('skipif.inc');
6: require_once('skipifconnectfailure.inc');
7: ?>
8: --FILE--
9: <?php
10: include "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:
17: if (!is_null($tmp = @mysql_fetch_assoc()))
18: printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
19:
20: if (NULL !== ($tmp = @mysql_fetch_assoc($link)))
21: printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
22:
23: require('table.inc');
24: if (!$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:
28: print "[005]\n";
29: var_dump(mysql_fetch_assoc($res));
30:
31: print "[006]\n";
32: var_dump(mysql_fetch_assoc($res));
33:
34: mysql_free_result($res);
35:
36: if (!$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: }
39: print "[008]\n";
40: var_dump(mysql_fetch_assoc($res));
41:
42: mysql_free_result($res);
43:
44: if (false !== ($tmp = mysql_fetch_assoc($res)))
45: printf("[008] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
46:
47: mysql_close($link);
48:
49: include('table.inc');
50: if (!$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: }
53: print "[010]\n";
54: var_dump(mysql_fetch_assoc($res));
55: mysql_free_result($res);
56:
57: mysql_close($link);
58:
59: print "done!";
60: ?>
61: --CLEAN--
62: <?php
63: require_once("clean_table.inc");
64: ?>
65: --EXPECTF--
66: [005]
67: array(2) {
68: [%u|b%"id"]=>
69: %unicode|string%(1) "1"
70: [%u|b%"label"]=>
71: %unicode|string%(1) "a"
72: }
73: [006]
74: bool(false)
75: [008]
76: array(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:
89: Warning: mysql_fetch_assoc(): %d is not a valid MySQL result resource in %s on line %d
90: [010]
91: array(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: }
103: done!
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>