Annotation of embedaddon/php/ext/mysqli/tests/mysqli_fetch_field.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: mysqli_fetch_field()
3: --SKIPIF--
4: <?php
5: require_once('skipif.inc');
6: require_once('skipifemb.inc');
7: require_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: if (!is_null($tmp = @mysqli_fetch_field()))
18: printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
19:
20: if (!is_null($tmp = @mysqli_fetch_field($link)))
21: printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
22:
23: require('table.inc');
24:
25: $charsets = my_get_charsets($link);
26: if (!$res = mysqli_query($link, "SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 1")) {
27: printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
28: }
29:
30: /* ID column, binary charset */
31: $tmp = mysqli_fetch_field($res);
32: var_dump($tmp);
33:
34: /* label column, result set charset */
35: $tmp = mysqli_fetch_field($res);
36: var_dump($tmp);
37: if ($tmp->charsetnr != $charsets['results']['nr']) {
38: printf("[004] Expecting charset %s/%d got %d\n",
39: $charsets['results']['charset'],
40: $charsets['results']['nr'], $tmp->charsetnr);
41: }
42: if ($tmp->length != (1 * $charsets['results']['maxlen'])) {
43: printf("[005] Expecting length %d got %d\n",
44: $charsets['results']['maxlen'],
45: $tmp->max_length);
46: }
47: if ($tmp->db != $db) {
48: printf("011] Expecting database '%s' got '%s'\n",
49: $db, $tmp->db);
50: }
51:
52: var_dump(mysqli_fetch_field($res));
53:
54: mysqli_free_result($res);
55:
56: // Read http://bugs.php.net/bug.php?id=42344 on defaults!
57: if (NULL !== ($tmp = mysqli_fetch_field($res)))
58: printf("[006] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
59:
60: if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
61: printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
62:
63: if (!mysqli_query($link, "CREATE TABLE test(id INT NOT NULL DEFAULT 1)"))
64: printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
65:
66: if (!mysqli_query($link, "INSERT INTO test(id) VALUES (2)"))
67: printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
68:
69: if (!$res = mysqli_query($link, "SELECT id as _default_test FROM test")) {
70: printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
71: }
72: var_dump(mysqli_fetch_assoc($res));
73: /* binary */
74: var_dump(mysqli_fetch_field($res));
75: mysqli_free_result($res);
76:
77: mysqli_close($link);
78:
79: print "done!";
80: ?>
81: --CLEAN--
82: <?php
83: require_once("clean_table.inc");
84: ?>
85: --EXPECTF--
86: object(stdClass)#%d (13) {
87: [%u|b%"name"]=>
88: %unicode|string%(2) "ID"
89: [%u|b%"orgname"]=>
90: %unicode|string%(2) "id"
91: [%u|b%"table"]=>
92: %unicode|string%(4) "TEST"
93: [%u|b%"orgtable"]=>
94: %unicode|string%(%d) "%s"
95: [%u|b%"def"]=>
96: %unicode|string%(0) ""
97: [%u|b%"db"]=>
98: %unicode|string%(%d) "%s"
99: [%u|b%"catalog"]=>
100: %unicode|string%(%d) "%s"
101: [%u|b%"max_length"]=>
102: int(1)
103: [%u|b%"length"]=>
104: int(11)
105: [%u|b%"charsetnr"]=>
106: int(63)
107: [%u|b%"flags"]=>
108: int(49155)
109: [%u|b%"type"]=>
110: int(3)
111: [%u|b%"decimals"]=>
112: int(0)
113: }
114: object(stdClass)#%d (13) {
115: [%u|b%"name"]=>
116: %unicode|string%(5) "label"
117: [%u|b%"orgname"]=>
118: %unicode|string%(5) "label"
119: [%u|b%"table"]=>
120: %unicode|string%(4) "TEST"
121: [%u|b%"orgtable"]=>
122: %unicode|string%(%d) "%s"
123: [%u|b%"def"]=>
124: %unicode|string%(0) ""
125: [%u|b%"db"]=>
126: %unicode|string%(%d) "%s"
127: [%u|b%"catalog"]=>
128: %unicode|string%(%d) "%s"
129: [%u|b%"max_length"]=>
130: int(%d)
131: [%u|b%"length"]=>
132: int(%d)
133: [%u|b%"charsetnr"]=>
134: int(%d)
135: [%u|b%"flags"]=>
136: int(0)
137: [%u|b%"type"]=>
138: int(254)
139: [%u|b%"decimals"]=>
140: int(0)
141: }
142: bool(false)
143:
144: Warning: mysqli_fetch_field(): Couldn't fetch mysqli_result in %s on line %d
145: array(1) {
146: [%u|b%"_default_test"]=>
147: %unicode|string%(1) "2"
148: }
149: object(stdClass)#%d (13) {
150: [%u|b%"name"]=>
151: %unicode|string%(13) "_default_test"
152: [%u|b%"orgname"]=>
153: %unicode|string%(2) "id"
154: [%u|b%"table"]=>
155: %unicode|string%(%d) "%s"
156: [%u|b%"orgtable"]=>
157: %unicode|string%(%d) "%s"
158: [%u|b%"def"]=>
159: %unicode|string%(0) ""
160: [%u|b%"db"]=>
161: %unicode|string%(%d) "%s"
162: [%u|b%"catalog"]=>
163: %unicode|string%(%d) "%s"
164: [%u|b%"max_length"]=>
165: int(1)
166: [%u|b%"length"]=>
167: int(11)
168: [%u|b%"charsetnr"]=>
169: int(63)
170: [%u|b%"flags"]=>
171: int(32769)
172: [%u|b%"type"]=>
173: int(3)
174: [%u|b%"decimals"]=>
175: int(0)
176: }
177: done!
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>