@@ -109,53 +109,84 @@ if (!function_exists('mysqli_stmt_get_result'))
109
109
110
110
mysqli_stmt_close ($ stmt );
111
111
112
+ // get_result cannot be used in PS cursor mode
112
113
if (!$ stmt = mysqli_stmt_init ($ link ))
113
- printf ("[032 ] [%d] %s \n" , mysqli_errno ($ link ), mysqli_error ($ link ));
114
+ printf ("[030 ] [%d] %s \n" , mysqli_errno ($ link ), mysqli_error ($ link ));
114
115
115
116
if (!mysqli_stmt_prepare ($ stmt , "SELECT id, label FROM test ORDER BY id LIMIT 2 " ))
117
+ printf ("[031] [%d] %s \n" , mysqli_stmt_errno ($ stmt ), mysqli_stmt_error ($ stmt ));
118
+
119
+ if (!mysqli_stmt_attr_set ($ stmt , MYSQLI_STMT_ATTR_CURSOR_TYPE , MYSQLI_CURSOR_TYPE_READ_ONLY ))
120
+ printf ("[032] [%d] %s \n" , mysqli_stmt_errno ($ stmt ), mysqli_stmt_error ($ stmt ));
121
+
122
+ if (!mysqli_stmt_execute ($ stmt ))
116
123
printf ("[033] [%d] %s \n" , mysqli_stmt_errno ($ stmt ), mysqli_stmt_error ($ stmt ));
117
124
125
+ mysqli_report (MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT );
126
+ try {
127
+ $ res = mysqli_stmt_get_result ($ stmt );
128
+ // we expect no segfault if we try to fetch a row because get_result should throw an error or return false
129
+ mysqli_fetch_assoc ($ res );
130
+ } catch (\mysqli_sql_exception $ e ) {
131
+ echo $ e ->getMessage () . "\n" ;
132
+ }
133
+
134
+ try {
135
+ $ res = $ stmt ->get_result ();
136
+ // we expect no segfault if we try to fetch a row because get_result should throw an error or return false
137
+ $ res ->fetch_assoc ();
138
+ } catch (\mysqli_sql_exception $ e ) {
139
+ echo $ e ->getMessage () . "\n" ;
140
+ }
141
+ mysqli_report (MYSQLI_REPORT_OFF );
142
+
143
+ if (!$ stmt = mysqli_stmt_init ($ link ))
144
+ printf ("[034] [%d] %s \n" , mysqli_errno ($ link ), mysqli_error ($ link ));
145
+
146
+ if (!mysqli_stmt_prepare ($ stmt , "SELECT id, label FROM test ORDER BY id LIMIT 2 " ))
147
+ printf ("[035] [%d] %s \n" , mysqli_stmt_errno ($ stmt ), mysqli_stmt_error ($ stmt ));
148
+
118
149
if (!mysqli_stmt_execute ($ stmt ))
119
- printf ("[034 ] [%d] %s \n" , mysqli_stmt_errno ($ stmt ), mysqli_stmt_error ($ stmt ));
150
+ printf ("[036 ] [%d] %s \n" , mysqli_stmt_errno ($ stmt ), mysqli_stmt_error ($ stmt ));
120
151
121
152
$ id = NULL ;
122
153
$ label = NULL ;
123
154
if (true !== ($ tmp = mysqli_stmt_bind_result ($ stmt , $ id , $ label )))
124
- printf ("[035 ] Expecting boolean/true, got %s/%s \n" , gettype ($ tmp ), var_export ($ tmp , 1 ));
155
+ printf ("[037 ] Expecting boolean/true, got %s/%s \n" , gettype ($ tmp ), var_export ($ tmp , 1 ));
125
156
126
157
if (!is_object ($ tmp = $ result = mysqli_stmt_get_result ($ stmt )))
127
- printf ("[036 ] Expecting array, got %s/%s, [%d] %s \n" ,
158
+ printf ("[038 ] Expecting array, got %s/%s, [%d] %s \n" ,
128
159
gettype ($ tmp ), var_export ($ tmp , 1 ),
129
160
mysqli_stmt_errno ($ stmt ), mysqli_stmt_error ($ stmt ));
130
161
131
162
if (false !== ($ tmp = mysqli_stmt_fetch ($ stmt )))
132
- printf ("[037 ] Expecting boolean/false, got %s/%s, [%d] %s \n" ,
163
+ printf ("[039 ] Expecting boolean/false, got %s/%s, [%d] %s \n" ,
133
164
gettype ($ tmp ), $ tmp , mysqli_stmt_errno ($ stmt ), mysqli_stmt_error ($ stmt ));
134
165
135
- printf ("[038 ] [%d] [%s] \n" , mysqli_stmt_errno ($ stmt ), mysqli_stmt_error ($ stmt ));
136
- printf ("[039 ] [%d] [%s] \n" , mysqli_errno ($ link ), mysqli_error ($ link ));
166
+ printf ("[040 ] [%d] [%s] \n" , mysqli_stmt_errno ($ stmt ), mysqli_stmt_error ($ stmt ));
167
+ printf ("[041 ] [%d] [%s] \n" , mysqli_errno ($ link ), mysqli_error ($ link ));
137
168
while ($ row = mysqli_fetch_assoc ($ result )) {
138
169
var_dump ($ row );
139
170
}
140
171
mysqli_free_result ($ result );
141
172
142
- if (!mysqli_kill ($ link , mysqli_thread_id ($ link )))
143
- printf ("[040 ] [%d] %s \n" , mysqli_errno ($ link ), mysqli_error ($ link ));
173
+ if (!mysqli_kill ($ link , mysqli_thread_id ($ link )))
174
+ printf ("[042 ] [%d] %s \n" , mysqli_errno ($ link ), mysqli_error ($ link ));
144
175
145
- if (false !== ($ tmp = mysqli_stmt_get_result ($ stmt )))
146
- printf ("[041 ] Expecting false, got %s/%s \n" , gettype ($ tmp ), var_export ($ tmp , 1 ));
176
+ if (false !== ($ tmp = mysqli_stmt_get_result ($ stmt )))
177
+ printf ("[043 ] Expecting false, got %s/%s \n" , gettype ($ tmp ), var_export ($ tmp , 1 ));
147
178
148
- mysqli_stmt_close ($ stmt );
179
+ mysqli_stmt_close ($ stmt );
149
180
150
- try {
181
+ try {
151
182
mysqli_stmt_fetch ($ stmt );
152
183
} catch (Error $ exception ) {
153
- echo $ exception ->getMessage () . "\n" ;
184
+ echo $ exception ->getMessage (), "\n" ;
154
185
}
155
186
156
- mysqli_close ($ link );
187
+ mysqli_close ($ link );
157
188
158
- print "done! " ;
189
+ print "done! " ;
159
190
?>
160
191
--CLEAN--
161
192
<?php
@@ -165,8 +196,10 @@ if (!function_exists('mysqli_stmt_get_result'))
165
196
mysqli_stmt object is not fully initialized
166
197
mysqli_stmt object is not fully initialized
167
198
mysqli_stmt object is not fully initialized
168
- [038] [2014] [Commands out of sync; you can't run this command now]
169
- [039] [0] []
199
+ mysqli_stmt_get_result() cannot be used with cursors
200
+ get_result() cannot be used with cursors
201
+ [040] [2014] [Commands out of sync; you can't run this command now]
202
+ [041] [0] []
170
203
array(2) {
171
204
["id"]=>
172
205
int(1)
0 commit comments