Annotation of embedaddon/php/ext/mysqli/tests/mysqli_stmt_get_result.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: mysqli_stmt_get_result()
3: --SKIPIF--
4: <?php
5: require_once('skipif.inc');
6: require_once('skipifemb.inc');
7: require_once('skipifconnectfailure.inc');
8:
9: if (!function_exists('mysqli_stmt_get_result'))
10: die('skip mysqli_stmt_get_result not available');
11: ?>
12: --FILE--
13: <?php
14: /*
15: NOTE: no datatype tests here! This is done by
16: mysqli_stmt_bind_result.phpt already. Restrict
17: this test case to the basics.
18: */
19: require_once("connect.inc");
20:
21: $tmp = NULL;
22: $link = NULL;
23:
24: if (!is_null($tmp = @mysqli_stmt_get_result()))
25: printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
26:
27: if (!is_null($tmp = @mysqli_stmt_get_result($link)))
28: printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
29:
30: require('table.inc');
31:
32: if (!$stmt = mysqli_stmt_init($link))
33: printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
34:
35: // stmt object status test
36: if (NULL !== ($tmp = mysqli_stmt_fetch($stmt)))
37: printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
38:
39: if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2"))
40: printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
41:
42: // FIXME - different versions return different values ?!
43: if ((NULL !== ($tmp = mysqli_stmt_get_result($stmt))) && (false !== $tmp))
44: printf("[006] Expecting NULL or boolean/false, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
45:
46: if (!mysqli_stmt_execute($stmt))
47: printf("[007] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
48:
49: if (!mysqli_stmt_store_result($stmt))
50: printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
51:
52: if (is_object($tmp = mysqli_stmt_store_result($stmt)))
53: printf("[009] non-object, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
54:
55: mysqli_stmt_close($stmt);
56:
57: if (!$stmt = mysqli_stmt_init($link))
58: printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
59:
60: // stmt object status test
61: if (NULL !== ($tmp = mysqli_stmt_fetch($stmt)))
62: printf("[011] Expecting NULL, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
63:
64: if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2"))
65: printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
66:
67: // FIXME - different versions return different values ?!
68: if ((NULL !== ($tmp = mysqli_stmt_get_result($stmt))) && (false !== $tmp))
69: printf("[013] Expecting NULL or boolean/false, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
70:
71: if (!mysqli_stmt_execute($stmt))
72: printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
73:
74: if (!is_object($tmp = mysqli_stmt_get_result($stmt)))
75: printf("[016] NULL, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
76:
77: mysqli_free_result($tmp);
78: mysqli_stmt_close($stmt);
79:
80: if (!$stmt = mysqli_stmt_init($link))
81: printf("[017] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
82:
83: // stmt object status test
84: if (NULL !== ($tmp = mysqli_stmt_get_result($stmt)))
85: printf("[018] Expecting NULL, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
86:
87: if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2"))
88: printf("[019] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
89:
90: if (false !== ($tmp = mysqli_stmt_get_result($stmt)))
91: printf("[020] Expecting false, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
92:
93: if (!mysqli_stmt_execute($stmt))
94: printf("[023] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
95:
96: if (!is_object($tmp = mysqli_stmt_get_result($stmt)))
97: printf("[024] Expecting object, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
98:
99: if (false !== ($tmp = mysqli_stmt_fetch($stmt)))
100: printf("[025] false, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
101:
102: if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id, $label))) {
103: printf("[026] [%d] [%s]\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
104: printf("[027] [%d] [%s]\n", mysqli_errno($link), mysqli_error($link));
105: printf("[028] Expecting boolean/true, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
106: }
107:
108: if (false !== ($tmp = mysqli_stmt_fetch($stmt)))
109: printf("[029] false, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
110:
111: mysqli_stmt_close($stmt);
112:
113: if (!$stmt = mysqli_stmt_init($link))
114: printf("[032] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
115:
116: if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2"))
117: printf("[033] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
118:
119: if (!mysqli_stmt_execute($stmt))
120: printf("[034] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
121:
122: $id = NULL;
123: $label = NULL;
124: if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id, $label)))
125: printf("[035] Expecting boolean/true, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
126:
127: if (!is_object($tmp = $result = mysqli_stmt_get_result($stmt)))
128: printf("[036] Expecting array, got %s/%s, [%d] %s\n",
129: gettype($tmp), var_export($tmp, 1),
130: mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
131:
132: if (false !== ($tmp = mysqli_stmt_fetch($stmt)))
133: printf("[037] Expecting boolean/false, got %s/%s, [%d] %s\n",
134: gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
135:
136: printf("[038] [%d] [%s]\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
137: printf("[039] [%d] [%s]\n", mysqli_errno($link), mysqli_error($link));
138: while ($row = mysqli_fetch_assoc($result)) {
139: var_dump($row);
140: }
141: mysqli_free_result($result);
142:
143: if (!mysqli_kill($link, mysqli_thread_id($link)))
144: printf("[040] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
145:
146: if (false !== ($tmp = mysqli_stmt_get_result($stmt)))
147: printf("[041] Expecting false, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
148:
149: mysqli_stmt_close($stmt);
150:
151: if (NULL !== ($tmp = mysqli_stmt_fetch($stmt)))
152: printf("[042] Expecting NULL, got %s/%s\n", gettype($tmp), var_export($tmp, 1));
153:
154: mysqli_close($link);
155:
156: print "done!";
157: ?>
158: --CLEAN--
159: <?php
160: require_once("clean_table.inc");
161: ?>
162: --EXPECTF--
163: Warning: mysqli_stmt_fetch(): invalid object or resource mysqli_stmt
164: in %s on line %d
165:
166: Warning: mysqli_stmt_fetch(): invalid object or resource mysqli_stmt
167: in %s on line %d
168:
169: Warning: mysqli_stmt_get_result(): invalid object or resource mysqli_stmt
170: in %s on line %d
171: [038] [2014] [Commands out of sync; you can't run this command now]
172: [039] [0] []
173: array(2) {
174: [%u|b%"id"]=>
175: int(1)
176: [%u|b%"label"]=>
177: %s(1) "a"
178: }
179: array(2) {
180: [%u|b%"id"]=>
181: int(2)
182: [%u|b%"label"]=>
183: %s(1) "b"
184: }
185:
186: Warning: mysqli_stmt_fetch(): Couldn't fetch mysqli_stmt in %s on line %d
187: done!
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>