1 : /*
2 : +----------------------------------------------------------------------+
3 : | PHP Version 6 |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) 1997-2009 The PHP Group |
6 : +----------------------------------------------------------------------+
7 : | This source file is subject to version 3.01 of the PHP license, |
8 : | that is bundled with this package in the file LICENSE, and is |
9 : | available through the world-wide-web at the following url: |
10 : | http://www.php.net/license/3_01.txt |
11 : | If you did not receive a copy of the PHP license and are unable to |
12 : | obtain it through the world-wide-web, please send a note to |
13 : | license@php.net so we can mail you a copy immediately. |
14 : +----------------------------------------------------------------------+
15 : | Authors: Georg Richter <georg@php.net> |
16 : | Andrey Hristov <andrey@php.net> |
17 : | Ulf Wendel <uw@php.net> |
18 : +----------------------------------------------------------------------+
19 :
20 : $Id: mysqli_api.c 290170 2009-11-03 14:56:04Z uw $
21 : */
22 :
23 : #ifdef HAVE_CONFIG_H
24 : #include "config.h"
25 : #endif
26 :
27 : #include <signal.h>
28 :
29 : #include "php.h"
30 : #include "php_ini.h"
31 : #include "php_globals.h"
32 : #include "ext/standard/info.h"
33 : #include "php_mysqli_structs.h"
34 : #include "ext/mysqlnd/mysqlnd_portability.h"
35 :
36 : /* {{{ proto mixed mysqli_affected_rows(object link) U
37 : Get number of affected rows in previous MySQL operation */
38 : PHP_FUNCTION(mysqli_affected_rows)
39 21 : {
40 : MY_MYSQL *mysql;
41 : zval *mysql_link;
42 : my_ulonglong rc;
43 :
44 21 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
45 3 : return;
46 : }
47 :
48 18 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
49 :
50 17 : rc = mysql_affected_rows(mysql->mysql);
51 17 : if (rc == (my_ulonglong) -1) {
52 1 : RETURN_LONG(-1);
53 : }
54 16 : MYSQLI_RETURN_LONG_LONG(rc);
55 : }
56 : /* }}} */
57 :
58 :
59 : /* {{{ proto bool mysqli_autocommit(object link, bool mode) U
60 : Turn auto commit on or of */
61 : PHP_FUNCTION(mysqli_autocommit)
62 30 : {
63 : MY_MYSQL *mysql;
64 : zval *mysql_link;
65 : zend_bool automode;
66 :
67 30 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ob", &mysql_link, mysqli_link_class_entry, &automode) == FAILURE) {
68 3 : return;
69 : }
70 27 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
71 :
72 25 : if (mysql_autocommit(mysql->mysql, automode)) {
73 0 : RETURN_FALSE;
74 : }
75 25 : RETURN_TRUE;
76 : }
77 : /* }}} */
78 :
79 : /* {{{ mysqli_stmt_bind_param_do_bind */
80 : #ifndef MYSQLI_USE_MYSQLND
81 : static
82 : int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int argc, unsigned int num_vars,
83 : zval ***args, unsigned int start, const char * const types TSRMLS_DC)
84 : {
85 : int i, ofs;
86 : MYSQL_BIND *bind;
87 : unsigned long rc;
88 :
89 : /* prevent leak if variables are already bound */
90 : if (stmt->param.var_cnt) {
91 : php_free_stmt_bind_buffer(stmt->param, FETCH_SIMPLE);
92 : }
93 :
94 : stmt->param.is_null = ecalloc(num_vars, sizeof(char));
95 : bind = (MYSQL_BIND *) ecalloc(num_vars, sizeof(MYSQL_BIND));
96 :
97 : ofs = 0;
98 : for (i = start; i < argc; i++) {
99 :
100 : /* set specified type */
101 : switch (types[ofs]) {
102 : case 'd': /* Double */
103 : bind[ofs].buffer_type = MYSQL_TYPE_DOUBLE;
104 : bind[ofs].buffer = &Z_DVAL_PP(args[i]);
105 : bind[ofs].is_null = &stmt->param.is_null[ofs];
106 : break;
107 :
108 : case 'i': /* Integer */
109 : #if SIZEOF_LONG==8
110 : bind[ofs].buffer_type = MYSQL_TYPE_LONGLONG;
111 : #elif SIZEOF_LONG==4
112 : bind[ofs].buffer_type = MYSQL_TYPE_LONG;
113 : #endif
114 : bind[ofs].buffer = &Z_LVAL_PP(args[i]);
115 : bind[ofs].is_null = &stmt->param.is_null[ofs];
116 : break;
117 :
118 : case 'b': /* Blob (send data) */
119 : bind[ofs].buffer_type = MYSQL_TYPE_LONG_BLOB;
120 : /* don't initialize is_null and length to 0 because we use ecalloc */
121 : break;
122 :
123 : case 's': /* string */
124 : bind[ofs].buffer_type = MYSQL_TYPE_VAR_STRING;
125 : /* don't initialize buffer and buffer_length because we use ecalloc */
126 : bind[ofs].is_null = &stmt->param.is_null[ofs];
127 : break;
128 :
129 : default:
130 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Undefined fieldtype %c (parameter %d)", types[ofs], i+1);
131 : rc = 1;
132 : goto end_1;
133 : }
134 : ofs++;
135 : }
136 : rc = mysql_stmt_bind_param(stmt->stmt, bind);
137 :
138 : end_1:
139 : if (rc) {
140 : efree(stmt->param.is_null);
141 : } else {
142 : stmt->param.var_cnt = num_vars;
143 : stmt->param.vars = (zval **)safe_emalloc(num_vars, sizeof(zval), 0);
144 : for (i = 0; i < num_vars; i++) {
145 : if (bind[i].buffer_type != MYSQL_TYPE_LONG_BLOB) {
146 : Z_ADDREF_P(*args[i+start]);
147 : stmt->param.vars[i] = *args[i+start];
148 : } else {
149 : stmt->param.vars[i] = NULL;
150 : }
151 : }
152 : }
153 : efree(bind);
154 :
155 : return rc;
156 : }
157 : #else
158 : static
159 : int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int argc, unsigned int num_vars,
160 : zval ***args, unsigned int start, const char * const types TSRMLS_DC)
161 20852 : {
162 : unsigned int i;
163 : MYSQLND_PARAM_BIND *params;
164 20852 : enum_func_status ret = FAIL;
165 :
166 : /* If no params -> skip binding and return directly */
167 20852 : if (argc == start) {
168 0 : return PASS;
169 : }
170 20852 : params = safe_emalloc(argc - start, sizeof(MYSQLND_PARAM_BIND), 0);
171 62554 : for (i = 0; i < (argc - start); i++) {
172 : zend_uchar type;
173 41704 : switch (types[i]) {
174 : case 'd': /* Double */
175 978 : type = MYSQL_TYPE_DOUBLE;
176 978 : break;
177 : case 'i': /* Integer */
178 : #if SIZEOF_LONG==8
179 : type = MYSQL_TYPE_LONGLONG;
180 : #elif SIZEOF_LONG==4
181 20478 : type = MYSQL_TYPE_LONG;
182 : #endif
183 20478 : break;
184 : case 'b': /* Blob (send data) */
185 24 : type = MYSQL_TYPE_LONG_BLOB;
186 24 : break;
187 : case 's': /* string */
188 20222 : type = MYSQL_TYPE_VAR_STRING;
189 20222 : break;
190 : default:
191 : /* We count parameters from 1 */
192 2 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Undefined fieldtype %c (parameter %d)", types[i], i + start + 1);
193 2 : ret = FAIL;
194 2 : efree(params);
195 2 : goto end;
196 : }
197 41702 : params[i].zv = *(args[i + start]);
198 41702 : params[i].type = type;
199 : }
200 20850 : ret = mysqlnd_stmt_bind_param(stmt->stmt, params);
201 :
202 20852 : end:
203 20852 : return ret;
204 : }
205 : #endif
206 : /* }}} */
207 :
208 : /* {{{ proto bool mysqli_stmt_bind_param(object stmt, string types, mixed variable [,mixed,....]) U
209 : Bind variables to a prepared statement as parameters */
210 : PHP_FUNCTION(mysqli_stmt_bind_param)
211 20863 : {
212 : zval ***args;
213 20863 : int argc = ZEND_NUM_ARGS();
214 : int num_vars;
215 20863 : int start = 2;
216 : MY_STMT *stmt;
217 : zval *mysql_stmt;
218 : char *types;
219 : int types_len;
220 : unsigned long rc;
221 :
222 : /* calculate and check number of parameters */
223 20863 : if (argc < 2) {
224 : /* there has to be at least one pair */
225 3 : WRONG_PARAM_COUNT;
226 : }
227 :
228 20860 : if (zend_parse_method_parameters((getThis()) ? 1:2 TSRMLS_CC, getThis(), "Os&", &mysql_stmt, mysqli_stmt_class_entry,
229 : &types, &types_len, UG(utf8_conv)) == FAILURE) {
230 1 : return;
231 : }
232 :
233 20859 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
234 :
235 20859 : num_vars = argc - 1;
236 20859 : if (getThis()) {
237 16 : start = 1;
238 : } else {
239 : /* ignore handle parameter in procedural interface*/
240 20843 : --num_vars;
241 : }
242 20859 : if (!types_len) {
243 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid type or no types specified");
244 1 : RETURN_FALSE;
245 : }
246 :
247 20858 : if (types_len != argc - start) {
248 : /* number of bind variables doesn't match number of elements in type definition string */
249 3 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of elements in type definition string doesn't match number of bind variables");
250 3 : RETURN_FALSE;
251 : }
252 :
253 20855 : if (types_len != mysql_stmt_param_count(stmt->stmt)) {
254 3 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of variables doesn't match number of parameters in prepared statement");
255 3 : RETURN_FALSE;
256 : }
257 :
258 20852 : args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);
259 :
260 20852 : if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
261 0 : zend_wrong_param_count(TSRMLS_C);
262 0 : rc = 1;
263 : } else {
264 20852 : rc = mysqli_stmt_bind_param_do_bind(stmt, argc, num_vars, args, start, types TSRMLS_CC);
265 20852 : MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
266 : }
267 :
268 20852 : efree(args);
269 :
270 20852 : RETURN_BOOL(!rc);
271 : }
272 : /* }}} */
273 :
274 : /* {{{ mysqli_stmt_bind_result_do_bind */
275 : #ifndef MYSQLI_USE_MYSQLND
276 : /* TODO:
277 : do_alloca, free_alloca
278 : */
279 : static int
280 : mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval ***args, unsigned int argc, unsigned int start TSRMLS_DC)
281 : {
282 : MYSQL_BIND *bind;
283 : int i, ofs;
284 : int var_cnt = argc - start;
285 : long col_type;
286 : ulong rc;
287 :
288 : /* prevent leak if variables are already bound */
289 : if (stmt->result.var_cnt) {
290 : php_free_stmt_bind_buffer(stmt->result, FETCH_RESULT);
291 : }
292 :
293 : bind = (MYSQL_BIND *)ecalloc(var_cnt, sizeof(MYSQL_BIND));
294 : {
295 : int size;
296 : char *p= emalloc(size= var_cnt * (sizeof(char) + sizeof(VAR_BUFFER)));
297 : stmt->result.buf = (VAR_BUFFER *) p;
298 : stmt->result.is_null = p + var_cnt * sizeof(VAR_BUFFER);
299 : memset(p, 0, size);
300 : }
301 :
302 : for (i=start; i < var_cnt + start ; i++) {
303 : ofs = i - start;
304 : col_type = (stmt->stmt->fields) ? stmt->stmt->fields[ofs].type : MYSQL_TYPE_STRING;
305 :
306 : switch (col_type) {
307 : case MYSQL_TYPE_DOUBLE:
308 : case MYSQL_TYPE_FLOAT:
309 : convert_to_double_ex(args[i]);
310 : stmt->result.buf[ofs].type = IS_DOUBLE;
311 : stmt->result.buf[ofs].buflen = sizeof(double);
312 :
313 : /* allocate buffer for double */
314 : stmt->result.buf[ofs].val = (char *)emalloc(sizeof(double));
315 : bind[ofs].buffer_type = MYSQL_TYPE_DOUBLE;
316 : bind[ofs].buffer = stmt->result.buf[ofs].val;
317 : bind[ofs].is_null = &stmt->result.is_null[ofs];
318 : break;
319 :
320 : case MYSQL_TYPE_NULL:
321 : stmt->result.buf[ofs].type = IS_NULL;
322 : /*
323 : don't initialize to 0 :
324 : 1. stmt->result.buf[ofs].buflen
325 : 2. bind[ofs].buffer
326 : 3. bind[ofs].buffer_length
327 : because memory was allocated with ecalloc
328 : */
329 : bind[ofs].buffer_type = MYSQL_TYPE_NULL;
330 : bind[ofs].is_null = &stmt->result.is_null[ofs];
331 : break;
332 :
333 : case MYSQL_TYPE_SHORT:
334 : case MYSQL_TYPE_TINY:
335 : case MYSQL_TYPE_LONG:
336 : case MYSQL_TYPE_INT24:
337 : case MYSQL_TYPE_YEAR:
338 : convert_to_long_ex(args[i]);
339 : stmt->result.buf[ofs].type = IS_LONG;
340 : /* don't set stmt->result.buf[ofs].buflen to 0, we used ecalloc */
341 : stmt->result.buf[ofs].val = (char *)emalloc(sizeof(int));
342 : bind[ofs].buffer_type = MYSQL_TYPE_LONG;
343 : bind[ofs].buffer = stmt->result.buf[ofs].val;
344 : bind[ofs].is_null = &stmt->result.is_null[ofs];
345 : bind[ofs].is_unsigned = (stmt->stmt->fields[ofs].flags & UNSIGNED_FLAG) ? 1 : 0;
346 : break;
347 :
348 : case MYSQL_TYPE_LONGLONG:
349 : #if MYSQL_VERSION_ID > 50002 || defined(MYSQLI_USE_MYSQLND)
350 : case MYSQL_TYPE_BIT:
351 : #endif
352 : stmt->result.buf[ofs].type = IS_STRING;
353 : stmt->result.buf[ofs].buflen = sizeof(my_ulonglong);
354 : stmt->result.buf[ofs].val = (char *)emalloc(stmt->result.buf[ofs].buflen);
355 : bind[ofs].buffer_type = col_type;
356 : bind[ofs].buffer = stmt->result.buf[ofs].val;
357 : bind[ofs].is_null = &stmt->result.is_null[ofs];
358 : bind[ofs].buffer_length = stmt->result.buf[ofs].buflen;
359 : bind[ofs].is_unsigned = (stmt->stmt->fields[ofs].flags & UNSIGNED_FLAG) ? 1 : 0;
360 : bind[ofs].length = &stmt->result.buf[ofs].output_len;
361 : break;
362 :
363 : case MYSQL_TYPE_DATE:
364 : case MYSQL_TYPE_TIME:
365 : case MYSQL_TYPE_DATETIME:
366 : case MYSQL_TYPE_NEWDATE:
367 : case MYSQL_TYPE_VAR_STRING:
368 : case MYSQL_TYPE_STRING:
369 : case MYSQL_TYPE_TINY_BLOB:
370 : case MYSQL_TYPE_BLOB:
371 : case MYSQL_TYPE_MEDIUM_BLOB:
372 : case MYSQL_TYPE_LONG_BLOB:
373 : case MYSQL_TYPE_TIMESTAMP:
374 : case MYSQL_TYPE_DECIMAL:
375 : case MYSQL_TYPE_GEOMETRY:
376 : #ifdef FIELD_TYPE_NEWDECIMAL
377 : case MYSQL_TYPE_NEWDECIMAL:
378 : #endif
379 : {
380 : #if MYSQL_VERSION_ID > 50099
381 : /* Changed to my_bool in MySQL 5.1. See MySQL Bug #16144 */
382 : my_bool tmp;
383 : #else
384 : ulong tmp = 0;
385 : #endif
386 : stmt->result.buf[ofs].type = IS_STRING;
387 : /*
388 : If the user has called $stmt->store_result() then we have asked
389 : max_length to be updated. this is done only for BLOBS because we don't want to allocate
390 : big chunkgs of memory 2^16 or 2^24
391 : */
392 : if (stmt->stmt->fields[ofs].max_length == 0 &&
393 : !mysql_stmt_attr_get(stmt->stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &tmp) && !tmp)
394 : {
395 : /*
396 : Allocate directly 256 because it's easier to allocate a bit more
397 : than update max length even for text columns. Try SELECT UNION SELECT UNION with
398 : different lengths and you will see that we get different lengths in stmt->stmt->fields[ofs].length
399 : The just take 256 and saves us from realloc-ing.
400 : */
401 : stmt->result.buf[ofs].buflen =
402 : (stmt->stmt->fields) ? (stmt->stmt->fields[ofs].length) ? stmt->stmt->fields[ofs].length + 1: 256: 256;
403 :
404 : } else {
405 : /*
406 : the user has called store_result(). if he does not there is no way to determine the
407 : libmysql does not allow us to allocate 0 bytes for a buffer so we try 1
408 : */
409 : if (!(stmt->result.buf[ofs].buflen = stmt->stmt->fields[ofs].max_length))
410 : ++stmt->result.buf[ofs].buflen;
411 : }
412 : stmt->result.buf[ofs].val = (char *)emalloc(stmt->result.buf[ofs].buflen);
413 : bind[ofs].buffer_type = MYSQL_TYPE_STRING;
414 : bind[ofs].buffer = stmt->result.buf[ofs].val;
415 : bind[ofs].is_null = &stmt->result.is_null[ofs];
416 : bind[ofs].buffer_length = stmt->result.buf[ofs].buflen;
417 : bind[ofs].length = &stmt->result.buf[ofs].output_len;
418 : break;
419 : }
420 : default:
421 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Server returned unknown type %ld. Probably your client library is incompatible with the server version you use!", col_type);
422 : break;
423 : }
424 : }
425 :
426 : rc = mysql_stmt_bind_result(stmt->stmt, bind);
427 : MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
428 :
429 : if (rc) {
430 : /* dont close the statement or subsequent usage (for example ->execute()) will lead to crash */
431 : for (i=0; i < var_cnt ; i++) {
432 : if (stmt->result.buf[i].val) {
433 : efree(stmt->result.buf[i].val);
434 : }
435 : }
436 : /* Don't free stmt->result.is_null because is_null & buf are one block of memory */
437 : efree(stmt->result.buf);
438 : } else {
439 : stmt->result.var_cnt = var_cnt;
440 : stmt->result.vars = (zval **)safe_emalloc((var_cnt), sizeof(zval), 0);
441 : for (i = start; i < var_cnt+start; i++) {
442 : ofs = i-start;
443 : Z_ADDREF_PP(args[i]);
444 : stmt->result.vars[ofs] = *args[i];
445 : }
446 : }
447 : efree(bind);
448 :
449 : return rc;
450 : }
451 : #else
452 : static int
453 : mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval ***args, unsigned int argc, unsigned int start TSRMLS_DC)
454 1262 : {
455 : unsigned int i;
456 : MYSQLND_RESULT_BIND *params;
457 :
458 1262 : params = safe_emalloc(argc - start, sizeof(MYSQLND_RESULT_BIND), 0);
459 6785 : for (i = 0; i < (argc - start); i++) {
460 5523 : params[i].zv = *(args[i + start]);
461 : }
462 1262 : return mysqlnd_stmt_bind_result(stmt->stmt, params);
463 : }
464 : #endif
465 : /* }}} */
466 :
467 : /* {{{ proto bool mysqli_stmt_bind_result(object stmt, mixed var, [,mixed, ...]) U
468 : Bind variables to a prepared statement for result storage */
469 : PHP_FUNCTION(mysqli_stmt_bind_result)
470 1270 : {
471 : zval ***args;
472 1270 : int argc = ZEND_NUM_ARGS();
473 1270 : int start = 1;
474 : ulong rc;
475 : MY_STMT *stmt;
476 : zval *mysql_stmt;
477 :
478 1270 : if (getThis()) {
479 35 : start = 0;
480 : }
481 :
482 1270 : if (zend_parse_method_parameters((getThis()) ? 0:1 TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
483 3 : return;
484 : }
485 :
486 1267 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
487 :
488 1266 : if (argc < (getThis() ? 1 : 2)) {
489 1 : WRONG_PARAM_COUNT;
490 : }
491 :
492 1265 : if ((argc - start) != mysql_stmt_field_count(stmt->stmt)) {
493 3 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of bind variables doesn't match number of fields in prepared statement");
494 3 : RETURN_FALSE;
495 : }
496 :
497 1262 : args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);
498 :
499 1262 : if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
500 0 : efree(args);
501 0 : WRONG_PARAM_COUNT;
502 : }
503 :
504 1262 : rc = mysqli_stmt_bind_result_do_bind(stmt, args, argc, start TSRMLS_CC);
505 :
506 1262 : efree(args);
507 :
508 1262 : RETURN_BOOL(!rc);
509 : }
510 : /* }}} */
511 :
512 : /* {{{ proto bool mysqli_change_user(object link, string user, string password, string database) U
513 : Change logged-in user of the active connection */
514 : PHP_FUNCTION(mysqli_change_user)
515 28 : {
516 : MY_MYSQL *mysql;
517 28 : zval *mysql_link = NULL;
518 : char *user, *password, *dbname;
519 : int user_len, password_len, dbname_len;
520 : ulong rc;
521 :
522 28 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os&s&s&", &mysql_link, mysqli_link_class_entry,
523 : &user, &user_len, UG(utf8_conv), &password, &password_len, UG(utf8_conv),
524 : &dbname, &dbname_len, UG(utf8_conv)) == FAILURE) {
525 9 : return;
526 : }
527 19 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
528 :
529 17 : rc = mysql_change_user(mysql->mysql, user, password, dbname);
530 17 : MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
531 :
532 17 : if (rc) {
533 11 : RETURN_FALSE;
534 : }
535 :
536 : /* Change user resets the charset in the server, change it back */
537 6 : mysql_set_character_set(mysql->mysql, "utf8");
538 :
539 6 : RETURN_TRUE;
540 : }
541 : /* }}} */
542 :
543 : /* {{{ proto string mysqli_character_set_name(object link) U
544 : Returns the name of the character set used for this connection */
545 : PHP_FUNCTION(mysqli_character_set_name)
546 13 : {
547 : MY_MYSQL *mysql;
548 : zval *mysql_link;
549 :
550 13 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
551 5 : return;
552 : }
553 :
554 8 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
555 :
556 5 : RETURN_UTF8_STRING((char *)mysql_character_set_name(mysql->mysql), ZSTR_DUPLICATE);
557 : }
558 : /* }}} */
559 :
560 : /* {{{ php_mysqli_close */
561 : void php_mysqli_close(MY_MYSQL * mysql, int close_type TSRMLS_DC)
562 1068 : {
563 1068 : if (!mysql->persistent) {
564 987 : mysqli_close(mysql->mysql, MYSQLI_CLOSE_EXPLICIT);
565 : } else {
566 : zend_rsrc_list_entry *le;
567 81 : if (zend_hash_find(&EG(persistent_list), mysql->hash_key, strlen(mysql->hash_key) + 1, (void **)&le) == SUCCESS) {
568 81 : if (Z_TYPE_P(le) == php_le_pmysqli()) {
569 81 : mysqli_plist_entry *plist = (mysqli_plist_entry *) le->ptr;
570 81 : zend_ptr_stack_push(&plist->free_links, mysql->mysql);
571 :
572 81 : MyG(num_links)--;
573 81 : MyG(num_active_persistent)--;
574 81 : MyG(num_inactive_persistent)++;
575 : }
576 : }
577 81 : mysql->persistent = FALSE;
578 : }
579 1068 : mysql->mysql = NULL;
580 :
581 1068 : php_clear_mysql(mysql);
582 1068 : }
583 : /* }}} */
584 :
585 :
586 : /* {{{ proto bool mysqli_close(object link) U
587 : Close connection */
588 : PHP_FUNCTION(mysqli_close)
589 953 : {
590 : zval *mysql_link;
591 : MY_MYSQL *mysql;
592 :
593 953 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
594 9 : return;
595 : }
596 :
597 944 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_INITIALIZED);
598 :
599 942 : php_mysqli_close(mysql, MYSQLI_CLOSE_EXPLICIT TSRMLS_CC);
600 :
601 942 : MYSQLI_CLEAR_RESOURCE(&mysql_link);
602 942 : efree(mysql);
603 942 : RETURN_TRUE;
604 : }
605 : /* }}} */
606 :
607 : /* {{{ proto bool mysqli_commit(object link) U
608 : Commit outstanding actions and close transaction */
609 : PHP_FUNCTION(mysqli_commit)
610 13 : {
611 : MY_MYSQL *mysql;
612 : zval *mysql_link;
613 :
614 13 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
615 4 : return;
616 : }
617 9 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
618 6 : if (mysql_commit(mysql->mysql)) {
619 1 : RETURN_FALSE;
620 : }
621 5 : RETURN_TRUE;
622 : }
623 : /* }}} */
624 :
625 : /* {{{ proto bool mysqli_data_seek(object result, int offset) U
626 : Move internal result pointer */
627 : PHP_FUNCTION(mysqli_data_seek)
628 132 : {
629 : MYSQL_RES *result;
630 : zval *mysql_result;
631 : long offset;
632 :
633 132 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &mysql_result, mysqli_result_class_entry, &offset) == FAILURE) {
634 6 : return;
635 : }
636 :
637 126 : MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
638 :
639 121 : if (mysqli_result_is_unbuffered(result)) {
640 3 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Function cannot be used with MYSQL_USE_RESULT");
641 3 : RETURN_FALSE;
642 : }
643 :
644 118 : if (offset < 0 || offset >= mysql_num_rows(result)) {
645 51 : RETURN_FALSE;
646 : }
647 :
648 67 : mysql_data_seek(result, offset);
649 67 : RETURN_TRUE;
650 : }
651 : /* }}} */
652 :
653 : /* {{{ proto void mysqli_debug(string debug) U
654 : */
655 : PHP_FUNCTION(mysqli_debug)
656 0 : {
657 : char *debug;
658 : int debug_len;
659 :
660 0 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s&", &debug, &debug_len, UG(utf8_conv)) == FAILURE) {
661 0 : return;
662 : }
663 :
664 0 : mysql_debug(debug);
665 0 : RETURN_TRUE;
666 : }
667 : /* }}} */
668 :
669 :
670 : /* {{{ proto bool mysqli_dump_debug_info(object link) U
671 : */
672 : PHP_FUNCTION(mysqli_dump_debug_info)
673 7 : {
674 : MY_MYSQL *mysql;
675 : zval *mysql_link;
676 :
677 7 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
678 3 : return;
679 : }
680 4 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
681 :
682 2 : RETURN_BOOL(!mysql_dump_debug_info(mysql->mysql))
683 : }
684 : /* }}} */
685 :
686 : /* {{{ proto int mysqli_errno(object link) U
687 : Returns the numerical value of the error message from previous MySQL operation */
688 : PHP_FUNCTION(mysqli_errno)
689 56 : {
690 : MY_MYSQL *mysql;
691 : zval *mysql_link;
692 :
693 56 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
694 2 : return;
695 : }
696 54 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
697 53 : RETURN_LONG(mysql_errno(mysql->mysql));
698 : }
699 : /* }}} */
700 :
701 : /* {{{ proto string mysqli_error(object link) U
702 : Returns the text of the error message from previous MySQL operation */
703 : PHP_FUNCTION(mysqli_error)
704 42 : {
705 : MY_MYSQL *mysql;
706 : zval *mysql_link;
707 :
708 42 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
709 4 : return;
710 : }
711 38 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
712 :
713 36 : RETURN_UTF8_STRING((char *)mysql_error(mysql->mysql), ZSTR_DUPLICATE);
714 : }
715 : /* }}} */
716 :
717 : #ifndef MYSQLI_USE_MYSQLND
718 : /* {{{ php_mysqli_stmt_copy_it */
719 : static void
720 : php_mysqli_stmt_copy_it(zval *** copies, zval *original, uint param_count, uint current)
721 : {
722 : if (!*copies) {
723 : *copies = ecalloc(param_count, sizeof(zval *));
724 : }
725 : MAKE_STD_ZVAL((*copies)[current]);
726 : *(*copies)[current] = *original;
727 : Z_SET_REFCOUNT_P((*copies)[current], 1);
728 : zval_copy_ctor((*copies)[current]);
729 : }
730 : /* }}} */
731 : #endif
732 :
733 : /* {{{ proto bool mysqli_stmt_execute(object stmt) U
734 : Execute a prepared statement */
735 : PHP_FUNCTION(mysqli_stmt_execute)
736 4131 : {
737 : MY_STMT *stmt;
738 : zval *mysql_stmt;
739 : #ifndef MYSQLI_USE_MYSQLND
740 : unsigned int i;
741 : zval **copies = NULL;
742 : #endif
743 :
744 4131 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
745 2 : return;
746 : }
747 4129 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
748 :
749 : #ifndef MYSQLI_USE_MYSQLND
750 : if (stmt->param.var_cnt) {
751 : int j;
752 : for (i = 0; i < stmt->param.var_cnt; i++) {
753 : for (j = i + 1; j < stmt->param.var_cnt; j++) {
754 : /* Oops, someone binding the same variable - clone */
755 : if (stmt->param.vars[j] == stmt->param.vars[i] && stmt->param.vars[i]) {
756 : php_mysqli_stmt_copy_it(&copies, stmt->param.vars[i], stmt->param.var_cnt, i);
757 : break;
758 : }
759 : }
760 : }
761 : }
762 : for (i = 0; i < stmt->param.var_cnt; i++) {
763 : if (stmt->param.vars[i]) {
764 : if ( !(stmt->param.is_null[i] = (stmt->param.vars[i]->type == IS_NULL)) ) {
765 : zval *the_var = copies && copies[i]? copies[i]:stmt->param.vars[i];
766 : switch (stmt->stmt->params[i].buffer_type) {
767 : case MYSQL_TYPE_VAR_STRING:
768 : if (Z_TYPE_P(the_var) == IS_UNICODE) {
769 : if (the_var == stmt->param.vars[i]) {
770 : php_mysqli_stmt_copy_it(&copies, stmt->param.vars[i], stmt->param.var_cnt, i);
771 : the_var = copies[i];
772 : }
773 : zval_unicode_to_string_ex(the_var, UG(utf8_conv) TSRMLS_CC);
774 : } else {
775 : if (the_var == stmt->param.vars[i] && Z_TYPE_P(stmt->param.vars[i]) != IS_STRING) {
776 : php_mysqli_stmt_copy_it(&copies, stmt->param.vars[i], stmt->param.var_cnt, i);
777 : the_var = copies[i];
778 : }
779 : convert_to_string_ex(&the_var);
780 : }
781 : stmt->stmt->params[i].buffer = Z_STRVAL_P(the_var);
782 : stmt->stmt->params[i].buffer_length = Z_STRLEN_P(the_var);
783 : break;
784 : case MYSQL_TYPE_DOUBLE:
785 : if (the_var == stmt->param.vars[i] && Z_TYPE_P(stmt->param.vars[i]) != IS_DOUBLE) {
786 : php_mysqli_stmt_copy_it(&copies, stmt->param.vars[i], stmt->param.var_cnt, i);
787 : the_var = copies[i];
788 : }
789 : convert_to_double_ex(&the_var);
790 : stmt->stmt->params[i].buffer = &Z_LVAL_P(the_var);
791 : break;
792 : case MYSQL_TYPE_LONGLONG:
793 : case MYSQL_TYPE_LONG:
794 : if (the_var == stmt->param.vars[i] && Z_TYPE_P(stmt->param.vars[i]) != IS_LONG) {
795 : php_mysqli_stmt_copy_it(&copies, stmt->param.vars[i], stmt->param.var_cnt, i);
796 : the_var = copies[i];
797 : }
798 : convert_to_long_ex(&the_var);
799 : stmt->stmt->params[i].buffer = &Z_LVAL_P(the_var);
800 : break;
801 : default:
802 : break;
803 : }
804 : }
805 : }
806 : }
807 : #endif
808 :
809 4126 : if (mysql_stmt_execute(stmt->stmt)) {
810 10 : MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
811 10 : RETVAL_FALSE;
812 : } else {
813 4116 : RETVAL_TRUE;
814 : }
815 :
816 : #ifndef MYSQLI_USE_MYSQLND
817 : if (copies) {
818 : for (i = 0; i < stmt->param.var_cnt; i++) {
819 : if (copies[i]) {
820 : zval_ptr_dtor(&copies[i]);
821 : }
822 : }
823 : efree(copies);
824 : }
825 : #endif
826 :
827 4126 : if (MyG(report_mode) & MYSQLI_REPORT_INDEX) {
828 0 : php_mysqli_report_index(stmt->query, mysqli_stmt_server_status(stmt->stmt) TSRMLS_CC);
829 : }
830 : }
831 : /* }}} */
832 :
833 :
834 :
835 : #if !defined(MYSQLI_USE_MYSQLND)
836 : #define MYSQL_BINARY_CHARSET_NR 63
837 :
838 : #if MYSQL_VERSION_ID > 50002
839 : /* We have BIT */
840 : #define IS_BINARY_DATA(f) (((f).type == MYSQL_TYPE_TINY_BLOB || (f).type == MYSQL_TYPE_BLOB || \
841 : (f).type == MYSQL_TYPE_MEDIUM_BLOB || (f).type == MYSQL_TYPE_LONG_BLOB || \
842 : (f).type == MYSQL_TYPE_BIT || (f).type == MYSQL_TYPE_VAR_STRING || (f).type == MYSQL_TYPE_VARCHAR ||\
843 : (f).type == MYSQL_TYPE_STRING) && (f).charsetnr == MYSQL_BINARY_CHARSET_NR)
844 : #else
845 : /* No BIT */
846 : #define IS_BINARY_DATA(f) (((f).type == MYSQL_TYPE_TINY_BLOB || (f).type == MYSQL_TYPE_BLOB || \
847 : (f).type == MYSQL_TYPE_MEDIUM_BLOB || (f).type == MYSQL_TYPE_LONG_BLOB || \
848 : (f).type == MYSQL_TYPE_VAR_STRING || (f).type == MYSQL_TYPE_VARCHAR ||\
849 : (f).type == MYSQL_TYPE_STRING) && (f).charsetnr == MYSQL_BINARY_CHARSET_NR)
850 : #endif
851 :
852 :
853 : /* {{{ void mysqli_stmt_fetch_libmysql
854 : Fetch results from a prepared statement into the bound variables */
855 : void mysqli_stmt_fetch_libmysql(INTERNAL_FUNCTION_PARAMETERS)
856 : {
857 : MY_STMT *stmt;
858 : zval *mysql_stmt;
859 : unsigned int i;
860 : ulong ret;
861 : unsigned int uval;
862 : my_ulonglong llval;
863 : MYSQL_RES *result_metadata = NULL;
864 : MYSQL_FIELD *fields;
865 :
866 :
867 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
868 : return;
869 : }
870 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
871 :
872 : /* reset buffers */
873 : for (i = 0; i < stmt->result.var_cnt; i++) {
874 : if (stmt->result.buf[i].type == IS_STRING) {
875 : memset(stmt->result.buf[i].val, 0, stmt->result.buf[i].buflen);
876 : }
877 : }
878 : result_metadata = mysql_stmt_result_metadata(stmt->stmt);
879 : fields = mysql_fetch_fields(result_metadata);
880 : ret = mysql_stmt_fetch(stmt->stmt);
881 : #ifdef MYSQL_DATA_TRUNCATED
882 : if (!ret || ret == MYSQL_DATA_TRUNCATED) {
883 : #else
884 : if (!ret) {
885 : #endif
886 : for (i = 0; i < stmt->result.var_cnt; i++) {
887 : /*
888 : QQ: Isn't it quite better to call zval_dtor(). What if the user has
889 : assigned a resource, or an array to the bound variable? We are going
890 : to leak probably. zval_dtor() will handle also Unicode/Non-unicode mode.
891 : */
892 : /* Even if the string is of length zero there is one byte alloced so efree() in all cases */
893 : if (Z_TYPE_P(stmt->result.vars[i]) == IS_STRING) {
894 : efree(stmt->result.vars[i]->value.str.val);
895 : }
896 : if (Z_TYPE_P(stmt->result.vars[i]) == IS_UNICODE) {
897 : USTR_FREE(stmt->result.vars[i]->value.ustr.val);
898 : }
899 : if (!stmt->result.is_null[i]) {
900 : switch (stmt->result.buf[i].type) {
901 : case IS_LONG:
902 : if ((stmt->stmt->fields[i].type == MYSQL_TYPE_LONG)
903 : && (stmt->stmt->fields[i].flags & UNSIGNED_FLAG))
904 : {
905 : /* unsigned int (11) */
906 : uval= *(unsigned int *) stmt->result.buf[i].val;
907 : #if SIZEOF_LONG==4
908 : if (uval > INT_MAX) {
909 : char *tmp, *p;
910 : int j=10;
911 : tmp= emalloc(11);
912 : p= &tmp[9];
913 : do {
914 : *p-- = (uval % 10) + 48;
915 : uval = uval / 10;
916 : } while (--j > 0);
917 : tmp[10]= '\0';
918 : /* unsigned int > INT_MAX is 10 digits - ALWAYS */
919 : ZVAL_UTF8_STRINGL(stmt->result.vars[i], tmp, 10, 0);
920 : efree(tmp);
921 : break;
922 : }
923 : #endif
924 : }
925 : if (stmt->stmt->fields[i].flags & UNSIGNED_FLAG) {
926 : ZVAL_LONG(stmt->result.vars[i], *(unsigned int *)stmt->result.buf[i].val);
927 : } else {
928 : ZVAL_LONG(stmt->result.vars[i], *(int *)stmt->result.buf[i].val);
929 : }
930 : break;
931 : case IS_DOUBLE:
932 : ZVAL_DOUBLE(stmt->result.vars[i], *(double *)stmt->result.buf[i].val);
933 : break;
934 : case IS_STRING:
935 : if (stmt->stmt->bind[i].buffer_type == MYSQL_TYPE_LONGLONG
936 : #if MYSQL_VERSION_ID > 50002
937 : || stmt->stmt->bind[i].buffer_type == MYSQL_TYPE_BIT
938 : #endif
939 : ) {
940 : my_bool uns= (stmt->stmt->fields[i].flags & UNSIGNED_FLAG)? 1:0;
941 : #if MYSQL_VERSION_ID > 50002
942 : if (stmt->stmt->bind[i].buffer_type == MYSQL_TYPE_BIT) {
943 : switch (stmt->result.buf[i].output_len) {
944 : case 8:llval = (my_ulonglong) bit_uint8korr(stmt->result.buf[i].val);break;
945 : case 7:llval = (my_ulonglong) bit_uint7korr(stmt->result.buf[i].val);break;
946 : case 6:llval = (my_ulonglong) bit_uint6korr(stmt->result.buf[i].val);break;
947 : case 5:llval = (my_ulonglong) bit_uint5korr(stmt->result.buf[i].val);break;
948 : case 4:llval = (my_ulonglong) bit_uint4korr(stmt->result.buf[i].val);break;
949 : case 3:llval = (my_ulonglong) bit_uint3korr(stmt->result.buf[i].val);break;
950 : case 2:llval = (my_ulonglong) bit_uint2korr(stmt->result.buf[i].val);break;
951 : case 1:llval = (my_ulonglong) uint1korr(stmt->result.buf[i].val);break;
952 : }
953 : } else
954 : #endif
955 : {
956 : llval= *(my_ulonglong *) stmt->result.buf[i].val;
957 : }
958 : #if SIZEOF_LONG==8
959 : if (uns && llval > 9223372036854775807L) {
960 : #elif SIZEOF_LONG==4
961 : if ((uns && llval > L64(2147483647)) ||
962 : (!uns && (( L64(2147483647) < (my_longlong) llval) ||
963 : (L64(-2147483648) > (my_longlong) llval))))
964 : {
965 : #endif
966 : char tmp[22];
967 : /* even though lval is declared as unsigned, the value
968 : * may be negative. Therefor we cannot use MYSQLI_LLU_SPEC and must
969 : * use MYSQLI_LL_SPEC.
970 : */
971 : snprintf(tmp, sizeof(tmp), (stmt->stmt->fields[i].flags & UNSIGNED_FLAG)? MYSQLI_LLU_SPEC : MYSQLI_LL_SPEC, llval);
972 : ZVAL_UTF8_STRING(stmt->result.vars[i], tmp, ZSTR_DUPLICATE);
973 : } else {
974 : ZVAL_LONG(stmt->result.vars[i], llval);
975 : }
976 : } else {
977 : size_t copy_len;
978 : #if defined(MYSQL_DATA_TRUNCATED) && MYSQL_VERSION_ID > 50002
979 : if (ret == MYSQL_DATA_TRUNCATED && *(stmt->stmt->bind[i].error) != 0) {
980 : /* result was truncated */
981 : copy_len = stmt->stmt->bind[i].buffer_length;
982 : } else
983 : #endif
984 : {
985 : copy_len = stmt->result.buf[i].output_len;
986 : }
987 : if (!IS_BINARY_DATA(fields[i])) {
988 : ZVAL_UTF8_STRINGL(stmt->result.vars[i], stmt->result.buf[i].val,
989 : copy_len, ZSTR_DUPLICATE);
990 : } else {
991 : ZVAL_STRINGL(stmt->result.vars[i], stmt->result.buf[i].val,
992 : copy_len, 1);
993 : }
994 : }
995 : break;
996 : default:
997 : break;
998 : }
999 : } else {
1000 : ZVAL_NULL(stmt->result.vars[i]);
1001 : }
1002 : }
1003 : } else {
1004 : MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
1005 : }
1006 : if (result_metadata) {
1007 : mysql_free_result(result_metadata);
1008 : result_metadata = NULL;
1009 : }
1010 :
1011 : switch (ret) {
1012 : case 0:
1013 : #ifdef MYSQL_DATA_TRUNCATED
1014 : /* according to SQL standard truncation (e.g. loss of precision is
1015 : not an error) - for detecting possible truncation you have to
1016 : check mysqli_stmt_warning
1017 : */
1018 : case MYSQL_DATA_TRUNCATED:
1019 : #endif
1020 : RETURN_TRUE;
1021 : break;
1022 : case 1:
1023 : RETURN_FALSE;
1024 : break;
1025 : default:
1026 : RETURN_NULL();
1027 : break;
1028 : }
1029 : }
1030 : /* }}} */
1031 : #else
1032 : /* {{{ mixed mysqli_stmt_fetch_mysqlnd */
1033 : void mysqli_stmt_fetch_mysqlnd(INTERNAL_FUNCTION_PARAMETERS)
1034 4933 : {
1035 : MY_STMT *stmt;
1036 : zval *mysql_stmt;
1037 : zend_bool fetched_anything;
1038 :
1039 4933 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
1040 3 : return;
1041 : }
1042 4930 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
1043 :
1044 4925 : if (FAIL == mysqlnd_stmt_fetch(stmt->stmt, &fetched_anything)) {
1045 8 : RETURN_BOOL(FALSE);
1046 4917 : } else if (fetched_anything == TRUE) {
1047 4769 : RETURN_BOOL(TRUE);
1048 : } else {
1049 148 : RETURN_NULL();
1050 : }
1051 : }
1052 : #endif
1053 : /* }}} */
1054 :
1055 :
1056 : /* {{{ proto mixed mysqli_stmt_fetch(object stmt) U
1057 : Fetch results from a prepared statement into the bound variables */
1058 : PHP_FUNCTION(mysqli_stmt_fetch)
1059 4933 : {
1060 : #if !defined(MYSQLI_USE_MYSQLND)
1061 : mysqli_stmt_fetch_libmysql(INTERNAL_FUNCTION_PARAM_PASSTHRU);
1062 : #else
1063 4933 : mysqli_stmt_fetch_mysqlnd(INTERNAL_FUNCTION_PARAM_PASSTHRU);
1064 : #endif
1065 4933 : }
1066 : /* }}} */
1067 :
1068 : /* {{{ php_add_field_properties */
1069 : static void php_add_field_properties(zval *value, const MYSQL_FIELD *field TSRMLS_DC)
1070 1250 : {
1071 1250 : add_property_utf8_string(value, "name",(field->name ? field->name : ""), ZSTR_DUPLICATE);
1072 1250 : add_property_utf8_string(value, "orgname",(field->org_name ? field->org_name : ""), ZSTR_DUPLICATE);
1073 1250 : add_property_utf8_string(value, "table",(field->table ? field->table : ""), ZSTR_DUPLICATE);
1074 1250 : add_property_utf8_string(value, "orgtable",(field->org_table ? field->org_table : ""), ZSTR_DUPLICATE);
1075 1250 : add_property_utf8_string(value, "def",(field->def ? field->def : ""), ZSTR_DUPLICATE);
1076 :
1077 1250 : add_property_long(value, "max_length", field->max_length);
1078 1250 : add_property_long(value, "length", field->length);
1079 1250 : add_property_long(value, "charsetnr", field->charsetnr);
1080 1250 : add_property_long(value, "flags", field->flags);
1081 1250 : add_property_long(value, "type", field->type);
1082 1250 : add_property_long(value, "decimals", field->decimals);
1083 1250 : }
1084 : /* }}} */
1085 :
1086 : /* {{{ proto mixed mysqli_fetch_field (object result) U
1087 : Get column information from a result and return as an object */
1088 : PHP_FUNCTION(mysqli_fetch_field)
1089 192 : {
1090 : MYSQL_RES *result;
1091 : zval *mysql_result;
1092 : const MYSQL_FIELD *field;
1093 :
1094 192 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
1095 3 : return;
1096 : }
1097 :
1098 189 : MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
1099 :
1100 183 : if (!(field = mysql_fetch_field(result))) {
1101 9 : RETURN_FALSE;
1102 : }
1103 :
1104 174 : object_init(return_value);
1105 174 : php_add_field_properties(return_value, field TSRMLS_CC);
1106 : }
1107 : /* }}} */
1108 :
1109 : /* {{{ proto mixed mysqli_fetch_fields (object result) U
1110 : Return array of objects containing field meta-data */
1111 : PHP_FUNCTION(mysqli_fetch_fields)
1112 514 : {
1113 : MYSQL_RES *result;
1114 : zval *mysql_result;
1115 : zval *obj;
1116 : unsigned int i;
1117 :
1118 514 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
1119 2 : return;
1120 : }
1121 :
1122 512 : MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
1123 :
1124 511 : array_init(return_value);
1125 :
1126 1549 : for (i = 0; i < mysql_num_fields(result); i++) {
1127 1038 : const MYSQL_FIELD *field = mysql_fetch_field_direct(result, i);
1128 :
1129 1038 : MAKE_STD_ZVAL(obj);
1130 1038 : object_init(obj);
1131 :
1132 1038 : php_add_field_properties(obj, field TSRMLS_CC);
1133 1038 : add_index_zval(return_value, i, obj);
1134 : }
1135 : }
1136 : /* }}} */
1137 :
1138 : /* {{{ proto mixed mysqli_fetch_field_direct (object result, int offset) U
1139 : Fetch meta-data for a single field */
1140 : PHP_FUNCTION(mysqli_fetch_field_direct)
1141 51 : {
1142 : MYSQL_RES *result;
1143 : zval *mysql_result;
1144 : const MYSQL_FIELD *field;
1145 : long offset;
1146 :
1147 51 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &mysql_result, mysqli_result_class_entry, &offset) == FAILURE) {
1148 7 : return;
1149 : }
1150 :
1151 44 : MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
1152 :
1153 42 : if (offset < 0 || offset >= (long) mysql_num_fields(result)) {
1154 4 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Field offset is invalid for resultset");
1155 4 : RETURN_FALSE;
1156 : }
1157 :
1158 38 : if (!(field = mysql_fetch_field_direct(result,offset))) {
1159 0 : RETURN_FALSE;
1160 : }
1161 :
1162 38 : object_init(return_value);
1163 38 : php_add_field_properties(return_value, field TSRMLS_CC);
1164 : }
1165 : /* }}} */
1166 :
1167 : /* {{{ proto mixed mysqli_fetch_lengths (object result) U
1168 : Get the length of each output in a result */
1169 : PHP_FUNCTION(mysqli_fetch_lengths)
1170 11 : {
1171 : MYSQL_RES *result;
1172 : zval *mysql_result;
1173 : unsigned int i;
1174 : unsigned long *ret;
1175 :
1176 11 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
1177 2 : return;
1178 : }
1179 :
1180 9 : MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
1181 :
1182 8 : if (!(ret = mysql_fetch_lengths(result))) {
1183 3 : RETURN_FALSE;
1184 : }
1185 :
1186 5 : array_init(return_value);
1187 :
1188 15 : for (i = 0; i < mysql_num_fields(result); i++) {
1189 10 : add_index_long(return_value, i, ret[i]);
1190 : }
1191 : }
1192 : /* }}} */
1193 :
1194 : /* {{{ proto array mysqli_fetch_row (object result) U
1195 : Get a result row as an enumerated array */
1196 : PHP_FUNCTION(mysqli_fetch_row)
1197 45 : {
1198 : #if !defined(MYSQLI_USE_MYSQLND)
1199 : php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, MYSQLI_NUM, 0);
1200 : #else
1201 : MYSQL_RES *result;
1202 : zval *mysql_result;
1203 :
1204 45 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
1205 2 : return;
1206 : }
1207 43 : MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
1208 42 : mysqlnd_fetch_into(result, MYSQLND_FETCH_NUM, return_value, MYSQLND_MYSQLI);
1209 : #endif
1210 : }
1211 : /* }}} */
1212 :
1213 : /* {{{ proto int mysqli_field_count(object link) U
1214 : Fetch the number of fields returned by the last query for the given link
1215 : */
1216 : PHP_FUNCTION(mysqli_field_count)
1217 18 : {
1218 : MY_MYSQL *mysql;
1219 : zval *mysql_link;
1220 :
1221 18 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
1222 2 : return;
1223 : }
1224 16 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
1225 :
1226 15 : RETURN_LONG(mysql_field_count(mysql->mysql));
1227 : }
1228 : /* }}} */
1229 :
1230 : /* {{{ proto int mysqli_field_seek(object result, int fieldnr) U
1231 : Set result pointer to a specified field offset
1232 : */
1233 : PHP_FUNCTION(mysqli_field_seek)
1234 215 : {
1235 : MYSQL_RES *result;
1236 : zval *mysql_result;
1237 : unsigned long fieldnr;
1238 :
1239 215 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &mysql_result, mysqli_result_class_entry, &fieldnr) == FAILURE) {
1240 4 : return;
1241 : }
1242 211 : MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
1243 :
1244 210 : if (fieldnr < 0 || fieldnr >= mysql_num_fields(result)) {
1245 79 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid field offset");
1246 79 : RETURN_FALSE;
1247 : }
1248 :
1249 131 : mysql_field_seek(result, fieldnr);
1250 131 : RETURN_TRUE;
1251 : }
1252 : /* }}} */
1253 :
1254 : /* {{{ proto int mysqli_field_tell(object result) U
1255 : Get current field offset of result pointer */
1256 : PHP_FUNCTION(mysqli_field_tell)
1257 140 : {
1258 : MYSQL_RES *result;
1259 : zval *mysql_result;
1260 :
1261 140 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
1262 3 : return;
1263 : }
1264 137 : MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
1265 :
1266 136 : RETURN_LONG(mysql_field_tell(result));
1267 : }
1268 : /* }}} */
1269 :
1270 : /* {{{ proto void mysqli_free_result(object result) U
1271 : Free query result memory for the given result handle */
1272 : PHP_FUNCTION(mysqli_free_result)
1273 2866 : {
1274 : MYSQL_RES *result;
1275 : zval *mysql_result;
1276 :
1277 2866 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
1278 5 : return;
1279 : }
1280 2861 : MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
1281 :
1282 2860 : mysqli_free_result(result, FALSE);
1283 2860 : MYSQLI_CLEAR_RESOURCE(&mysql_result);
1284 : }
1285 : /* }}} */
1286 :
1287 : /* {{{ proto string mysqli_get_client_info(void) U
1288 : Get MySQL client info */
1289 : PHP_FUNCTION(mysqli_get_client_info)
1290 1645 : {
1291 1645 : RETURN_UTF8_STRING((char *)mysql_get_client_info(), ZSTR_DUPLICATE);
1292 : }
1293 : /* }}} */
1294 :
1295 : /* {{{ proto int mysqli_get_client_version(void) U
1296 : Get MySQL client info */
1297 : PHP_FUNCTION(mysqli_get_client_version)
1298 12 : {
1299 12 : RETURN_LONG((long)mysql_get_client_version());
1300 : }
1301 : /* }}} */
1302 :
1303 : /* {{{ proto string mysqli_get_host_info (object link) U
1304 : Get MySQL host info */
1305 : PHP_FUNCTION(mysqli_get_host_info)
1306 7 : {
1307 : MY_MYSQL *mysql;
1308 7 : zval *mysql_link = NULL;
1309 :
1310 7 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
1311 2 : return;
1312 : }
1313 5 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
1314 :
1315 5 : RETURN_UTF8_STRING((mysql->mysql->host_info) ? mysql->mysql->host_info : "", ZSTR_DUPLICATE);
1316 : }
1317 : /* }}} */
1318 :
1319 : /* {{{ proto int mysqli_get_proto_info(object link) U
1320 : Get MySQL protocol information */
1321 : PHP_FUNCTION(mysqli_get_proto_info)
1322 8 : {
1323 : MY_MYSQL *mysql;
1324 8 : zval *mysql_link = NULL;
1325 :
1326 8 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
1327 3 : return;
1328 : }
1329 5 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
1330 5 : RETURN_LONG(mysql_get_proto_info(mysql->mysql));
1331 : }
1332 : /* }}} */
1333 :
1334 : /* {{{ proto string mysqli_get_server_info(object link) U
1335 : Get MySQL server info */
1336 : PHP_FUNCTION(mysqli_get_server_info)
1337 8 : {
1338 : MY_MYSQL *mysql;
1339 8 : zval *mysql_link = NULL;
1340 :
1341 8 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
1342 3 : return;
1343 : }
1344 5 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
1345 :
1346 5 : RETURN_UTF8_STRING((char *)mysql_get_server_info(mysql->mysql), ZSTR_DUPLICATE);
1347 : }
1348 :
1349 : /* }}} */
1350 :
1351 : /* {{{ proto int mysqli_get_server_version(object link) U
1352 : Return the MySQL version for the server referenced by the given link */
1353 : PHP_FUNCTION(mysqli_get_server_version)
1354 35 : {
1355 : MY_MYSQL *mysql;
1356 35 : zval *mysql_link = NULL;
1357 :
1358 35 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
1359 2 : return;
1360 : }
1361 33 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
1362 :
1363 33 : RETURN_LONG(mysql_get_server_version(mysql->mysql));
1364 : }
1365 : /* }}} */
1366 :
1367 : /* {{{ proto string mysqli_info(object link) U
1368 : Get information about the most recent query */
1369 : PHP_FUNCTION(mysqli_info)
1370 15 : {
1371 : MY_MYSQL *mysql;
1372 15 : zval *mysql_link = NULL;
1373 : const char *info;
1374 :
1375 15 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
1376 2 : return;
1377 : }
1378 13 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
1379 :
1380 13 : info = mysql_info(mysql->mysql);
1381 13 : RETURN_UTF8_STRING((info) ? info : "", ZSTR_DUPLICATE);
1382 : }
1383 : /* }}} */
1384 :
1385 : /* {{{ proto resource mysqli_init(void) U
1386 : Initialize mysqli and return a resource for use with mysql_real_connect */
1387 : PHP_FUNCTION(mysqli_init)
1388 1008 : {
1389 : MYSQLI_RESOURCE *mysqli_resource;
1390 : MY_MYSQL *mysql;
1391 :
1392 1008 : if (getThis() && ((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->ptr) {
1393 1 : return;
1394 : }
1395 :
1396 1007 : mysql = (MY_MYSQL *)ecalloc(1, sizeof(MY_MYSQL));
1397 :
1398 : #if !defined(MYSQLI_USE_MYSQLND)
1399 : if (!(mysql->mysql = mysql_init(NULL)))
1400 : #else
1401 : /*
1402 : We create always persistent, as if the user want to connecto
1403 : to p:somehost, we can't convert the handle then
1404 : */
1405 1007 : if (!(mysql->mysql = mysql_init(TRUE)))
1406 : #endif
1407 : {
1408 0 : efree(mysql);
1409 0 : RETURN_FALSE;
1410 : }
1411 :
1412 1007 : mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
1413 1007 : mysqli_resource->ptr = (void *)mysql;
1414 1007 : mysqli_resource->status = MYSQLI_STATUS_INITIALIZED;
1415 :
1416 1974 : if (!getThis() || !instanceof_function(Z_OBJCE_P(getThis()), mysqli_link_class_entry TSRMLS_CC)) {
1417 967 : MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_link_class_entry);
1418 : } else {
1419 40 : ((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->ptr = mysqli_resource;
1420 : }
1421 : }
1422 : /* }}} */
1423 :
1424 : /* {{{ proto mixed mysqli_insert_id(object link) U
1425 : Get the ID generated from the previous INSERT operation */
1426 : PHP_FUNCTION(mysqli_insert_id)
1427 22 : {
1428 : MY_MYSQL *mysql;
1429 : my_ulonglong rc;
1430 : zval *mysql_link;
1431 :
1432 22 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
1433 3 : return;
1434 : }
1435 19 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
1436 18 : rc = mysql_insert_id(mysql->mysql);
1437 18 : MYSQLI_RETURN_LONG_LONG(rc)
1438 : }
1439 : /* }}} */
1440 :
1441 : /* {{{ proto bool mysqli_kill(object link, int processid) U
1442 : Kill a mysql process on the server */
1443 : PHP_FUNCTION(mysqli_kill)
1444 26 : {
1445 : MY_MYSQL *mysql;
1446 : zval *mysql_link;
1447 : long processid;
1448 :
1449 26 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &mysql_link, mysqli_link_class_entry, &processid) == FAILURE) {
1450 2 : return;
1451 : }
1452 24 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
1453 :
1454 24 : if (processid <= 0) {
1455 7 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "processid should have positive value");
1456 7 : RETURN_FALSE;
1457 : }
1458 :
1459 17 : if (mysql_kill(mysql->mysql, processid)) {
1460 3 : MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
1461 3 : RETURN_FALSE;
1462 : }
1463 14 : RETURN_TRUE;
1464 : }
1465 : /* }}} */
1466 :
1467 : /* {{{ proto void mysqli_set_local_infile_default(object link) U
1468 : unsets user defined handler for load local infile command */
1469 : #if !defined(MYSQLI_USE_MYSQLND)
1470 : PHP_FUNCTION(mysqli_set_local_infile_default)
1471 : {
1472 : MY_MYSQL *mysql;
1473 : zval *mysql_link;
1474 :
1475 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
1476 : return;
1477 : }
1478 :
1479 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
1480 :
1481 : if (mysql->li_read) {
1482 : zval_ptr_dtor(&(mysql->li_read));
1483 : mysql->li_read = NULL;
1484 : }
1485 : }
1486 : /* }}} */
1487 :
1488 : /* {{{ proto bool mysqli_set_local_infile_handler(object link, callback read_func) U
1489 : Set callback functions for LOAD DATA LOCAL INFILE */
1490 : PHP_FUNCTION(mysqli_set_local_infile_handler)
1491 : {
1492 : MY_MYSQL *mysql;
1493 : zval *mysql_link;
1494 : zval callback_name;
1495 : zval *callback_func;
1496 :
1497 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oz", &mysql_link, mysqli_link_class_entry,
1498 : &callback_func) == FAILURE) {
1499 : return;
1500 : }
1501 :
1502 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
1503 :
1504 : if (Z_TYPE_P(callback_func) != IS_ARRAY && Z_TYPE_P(callback_func) != IS_OBJECT) {
1505 : convert_to_string(callback_func);
1506 : }
1507 :
1508 : /* check callback function */
1509 : if (!zend_is_callable(callback_func, 0, &callback_name TSRMLS_CC)) {
1510 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not a valid callback function %R", Z_TYPE(callback_name), Z_UNIVAL(callback_name));
1511 : zval_dtor(&callback_name);
1512 : RETURN_FALSE;
1513 : }
1514 : zval_dtor(&callback_name);
1515 :
1516 : /* save callback function */
1517 : if (!mysql->li_read) {
1518 : MAKE_STD_ZVAL(mysql->li_read);
1519 : } else {
1520 : zval_dtor(mysql->li_read);
1521 : }
1522 : ZVAL_ZVAL(mysql->li_read, callback_func, 1, 0);
1523 :
1524 : RETURN_TRUE;
1525 : }
1526 : #endif
1527 : /* }}} */
1528 :
1529 : /* {{{ proto bool mysqli_more_results(object link) U
1530 : check if there any more query results from a multi query */
1531 : PHP_FUNCTION(mysqli_more_results)
1532 31 : {
1533 : MY_MYSQL *mysql;
1534 : zval *mysql_link;
1535 :
1536 31 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
1537 2 : return;
1538 : }
1539 29 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
1540 :
1541 28 : RETURN_BOOL(mysql_more_results(mysql->mysql));
1542 : }
1543 : /* }}} */
1544 :
1545 : /* {{{ proto bool mysqli_next_result(object link) U
1546 : read next result from multi_query */
1547 40 : PHP_FUNCTION(mysqli_next_result) {
1548 : MY_MYSQL *mysql;
1549 : zval *mysql_link;
1550 :
1551 40 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
1552 2 : return;
1553 : }
1554 38 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
1555 :
1556 37 : if (!mysql_more_results(mysql->mysql)) {
1557 12 : php_error_docref(NULL TSRMLS_CC, E_STRICT, "There is no next result set. "
1558 : "Please, call mysqli_more_results()/mysqli::more_results() to check "
1559 : "whether to call this function/method");
1560 : }
1561 :
1562 37 : RETURN_BOOL(!mysql_next_result(mysql->mysql));
1563 : }
1564 : /* }}} */
1565 :
1566 :
1567 : #if defined(HAVE_STMT_NEXT_RESULT) && defined(MYSQLI_USE_MYSQLND)
1568 : /* {{{ proto bool mysqli_stmt_next_result(object link)
1569 : check if there any more query results from a multi query */
1570 : PHP_FUNCTION(mysqli_stmt_more_results)
1571 0 : {
1572 : MY_STMT *stmt;
1573 : zval *mysql_stmt;
1574 :
1575 0 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
1576 0 : return;
1577 : }
1578 0 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
1579 :
1580 0 : RETURN_BOOL(mysqlnd_stmt_more_results(stmt->stmt));
1581 : }
1582 : /* }}} */
1583 :
1584 :
1585 : /* {{{ proto bool mysqli_stmt_next_result(object link)
1586 : read next result from multi_query */
1587 0 : PHP_FUNCTION(mysqli_stmt_next_result) {
1588 : MY_STMT *stmt;
1589 : zval *mysql_stmt;
1590 :
1591 0 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
1592 0 : return;
1593 : }
1594 0 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
1595 :
1596 0 : if (!mysqlnd_stmt_more_results(stmt->stmt)) {
1597 0 : php_error_docref(NULL TSRMLS_CC, E_STRICT, "There is no next result set. "
1598 : "Please, call mysqli_stmt_more_results()/mysqli_stmt::more_results() to check "
1599 : "whether to call this function/method");
1600 : }
1601 :
1602 0 : RETURN_BOOL(!mysql_stmt_next_result(stmt->stmt));
1603 : }
1604 : /* }}} */
1605 : #endif
1606 :
1607 :
1608 : /* {{{ proto int mysqli_num_fields(object result) U
1609 : Get number of fields in result */
1610 : PHP_FUNCTION(mysqli_num_fields)
1611 12 : {
1612 : MYSQL_RES *result;
1613 : zval *mysql_result;
1614 :
1615 12 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
1616 2 : return;
1617 : }
1618 10 : MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
1619 :
1620 9 : RETURN_LONG(mysql_num_fields(result));
1621 : }
1622 : /* }}} */
1623 :
1624 : /* {{{ proto mixed mysqli_num_rows(object result) U
1625 : Get number of rows in result */
1626 : PHP_FUNCTION(mysqli_num_rows)
1627 24 : {
1628 : MYSQL_RES *result;
1629 : zval *mysql_result;
1630 :
1631 24 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
1632 3 : return;
1633 : }
1634 21 : MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
1635 :
1636 20 : if (mysqli_result_is_unbuffered(result)) {
1637 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Function cannot be used with MYSQL_USE_RESULT");
1638 1 : RETURN_LONG(0);
1639 : }
1640 :
1641 19 : MYSQLI_RETURN_LONG_LONG(mysql_num_rows(result));
1642 : }
1643 : /* }}} */
1644 :
1645 : /* {{{ mysqli_options_get_option_zval_type */
1646 : static int mysqli_options_get_option_zval_type(int option)
1647 20023 : {
1648 20023 : switch (option) {
1649 : #ifdef MYSQLI_USE_MYSQLND
1650 : #if PHP_MAJOR_VERSION >= 6
1651 : case MYSQLND_OPT_NUMERIC_AND_DATETIME_AS_UNICODE:
1652 : #endif
1653 : case MYSQLND_OPT_NET_CMD_BUFFER_SIZE:
1654 : case MYSQLND_OPT_NET_READ_BUFFER_SIZE:
1655 : #ifdef MYSQLND_STRING_TO_INT_CONVERSION
1656 : case MYSQLND_OPT_INT_AND_FLOAT_NATIVE:
1657 : #endif
1658 : #endif /* MYSQLI_USE_MYSQLND */
1659 : case MYSQL_OPT_CONNECT_TIMEOUT:
1660 : case MYSQL_REPORT_DATA_TRUNCATION:
1661 : case MYSQL_OPT_LOCAL_INFILE:
1662 : case MYSQL_OPT_NAMED_PIPE:
1663 : #ifdef MYSQL_OPT_PROTOCOL
1664 : case MYSQL_OPT_PROTOCOL:
1665 : #endif /* MySQL 4.1.0 */
1666 : #ifdef MYSQL_OPT_READ_TIMEOUT
1667 : case MYSQL_OPT_READ_TIMEOUT:
1668 : case MYSQL_OPT_WRITE_TIMEOUT:
1669 : case MYSQL_OPT_GUESS_CONNECTION:
1670 : case MYSQL_OPT_USE_EMBEDDED_CONNECTION:
1671 : case MYSQL_OPT_USE_REMOTE_CONNECTION:
1672 : case MYSQL_SECURE_AUTH:
1673 : #endif /* MySQL 4.1.1 */
1674 : #ifdef MYSQL_OPT_RECONNECT
1675 : case MYSQL_OPT_RECONNECT:
1676 : #endif /* MySQL 5.0.13 */
1677 : #ifdef MYSQL_OPT_SSL_VERIFY_SERVER_CERT
1678 : case MYSQL_OPT_SSL_VERIFY_SERVER_CERT:
1679 : #endif /* MySQL 5.0.23 */
1680 : #ifdef MYSQL_OPT_COMPRESS
1681 : case MYSQL_OPT_COMPRESS:
1682 : #endif /* mysqlnd @ PHP 5.3.2 */
1683 16 : return IS_LONG;
1684 :
1685 : #ifdef MYSQL_SHARED_MEMORY_BASE_NAME
1686 : case MYSQL_SHARED_MEMORY_BASE_NAME:
1687 : #endif /* MySQL 4.1.0 */
1688 : #ifdef MYSQL_SET_CLIENT_IP
1689 : case MYSQL_SET_CLIENT_IP:
1690 : #endif /* MySQL 4.1.1 */
1691 : case MYSQL_READ_DEFAULT_FILE:
1692 : case MYSQL_READ_DEFAULT_GROUP:
1693 : case MYSQL_INIT_COMMAND:
1694 : case MYSQL_SET_CHARSET_NAME:
1695 : case MYSQL_SET_CHARSET_DIR:
1696 18 : return IS_STRING;
1697 :
1698 : default:
1699 19989 : return IS_NULL;
1700 : }
1701 : }
1702 : /* }}} */
1703 :
1704 : /* {{{ proto bool mysqli_options(object link, int flags, mixed values) U
1705 : Set options */
1706 : PHP_FUNCTION(mysqli_options)
1707 20036 : {
1708 : MY_MYSQL *mysql;
1709 20036 : zval *mysql_link = NULL;
1710 : zval *mysql_value;
1711 : long mysql_option;
1712 : unsigned int l_value;
1713 : long ret;
1714 : int expected_type;
1715 :
1716 20036 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Olz", &mysql_link, mysqli_link_class_entry, &mysql_option, &mysql_value) == FAILURE) {
1717 10 : return;
1718 : }
1719 20026 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_INITIALIZED);
1720 :
1721 20024 : if (PG(open_basedir) && PG(open_basedir)[0] != '\0') {
1722 1 : if(mysql_option == MYSQL_OPT_LOCAL_INFILE) {
1723 1 : RETURN_FALSE;
1724 : }
1725 : }
1726 :
1727 20023 : expected_type = mysqli_options_get_option_zval_type(mysql_option);
1728 20023 : if (expected_type != Z_TYPE_P(mysql_value)) {
1729 20011 : switch (expected_type) {
1730 : case IS_STRING:
1731 18 : convert_to_string_ex(&mysql_value);
1732 18 : break;
1733 : case IS_LONG:
1734 4 : convert_to_long_ex(&mysql_value);
1735 : break;
1736 : default:
1737 : break;
1738 : }
1739 : }
1740 :
1741 20023 : switch (expected_type) {
1742 : case IS_STRING:
1743 18 : ret = mysql_options(mysql->mysql, mysql_option, Z_STRVAL_PP(&mysql_value));
1744 18 : break;
1745 : case IS_LONG:
1746 16 : l_value = Z_LVAL_PP(&mysql_value);
1747 16 : ret = mysql_options(mysql->mysql, mysql_option, (char *)&l_value);
1748 16 : break;
1749 : default:
1750 19989 : ret = 1;
1751 : break;
1752 : }
1753 :
1754 20023 : RETURN_BOOL(!ret);
1755 : }
1756 : /* }}} */
1757 :
1758 :
1759 : /* {{{ proto bool mysqli_ping(object link) U
1760 : Ping a server connection or reconnect if there is no connection */
1761 : PHP_FUNCTION(mysqli_ping)
1762 14 : {
1763 : MY_MYSQL *mysql;
1764 : zval *mysql_link;
1765 : long rc;
1766 :
1767 14 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
1768 2 : return;
1769 : }
1770 12 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
1771 11 : rc = mysql_ping(mysql->mysql);
1772 11 : MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
1773 :
1774 11 : RETURN_BOOL(!rc);
1775 : }
1776 : /* }}} */
1777 :
1778 : /* {{{ proto mixed mysqli_prepare(object link, string query) U
1779 : Prepare a SQL statement for execution */
1780 : PHP_FUNCTION(mysqli_prepare)
1781 114 : {
1782 : MY_MYSQL *mysql;
1783 : MY_STMT *stmt;
1784 114 : char *query = NULL;
1785 : unsigned int query_len;
1786 : zval *mysql_link;
1787 : MYSQLI_RESOURCE *mysqli_resource;
1788 :
1789 114 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os&",&mysql_link, mysqli_link_class_entry,
1790 : &query, &query_len, UG(utf8_conv)) == FAILURE) {
1791 2 : return;
1792 : }
1793 112 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
1794 :
1795 : #if !defined(MYSQLI_USE_MYSQLND)
1796 : if (mysql->mysql->status == MYSQL_STATUS_GET_RESULT) {
1797 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "All data must be fetched before a new statement prepare takes place");
1798 : RETURN_FALSE;
1799 : }
1800 : #endif
1801 :
1802 112 : stmt = (MY_STMT *)ecalloc(1,sizeof(MY_STMT));
1803 :
1804 112 : if ((stmt->stmt = mysql_stmt_init(mysql->mysql))) {
1805 112 : if (mysql_stmt_prepare(stmt->stmt, query, query_len)) {
1806 : /* mysql_stmt_close() clears errors, so we have to store them temporarily */
1807 : #if !defined(MYSQLI_USE_MYSQLND)
1808 : char last_error[MYSQL_ERRMSG_SIZE];
1809 : char sqlstate[SQLSTATE_LENGTH+1];
1810 : unsigned int last_errno;
1811 :
1812 : last_errno = stmt->stmt->last_errno;
1813 : memcpy(last_error, stmt->stmt->last_error, MYSQL_ERRMSG_SIZE);
1814 : memcpy(sqlstate, mysql->mysql->net.sqlstate, SQLSTATE_LENGTH+1);
1815 : #else
1816 10 : mysqlnd_error_info error_info = mysql->mysql->error_info;
1817 : #endif
1818 10 : mysqli_stmt_close(stmt->stmt, FALSE);
1819 10 : stmt->stmt = NULL;
1820 :
1821 : /* restore error messages */
1822 : #if !defined(MYSQLI_USE_MYSQLND)
1823 : mysql->mysql->net.last_errno = last_errno;
1824 : memcpy(mysql->mysql->net.last_error, last_error, MYSQL_ERRMSG_SIZE);
1825 : memcpy(mysql->mysql->net.sqlstate, sqlstate, SQLSTATE_LENGTH+1);
1826 : #else
1827 10 : mysql->mysql->error_info = error_info;
1828 : #endif
1829 : }
1830 : }
1831 :
1832 : /* don't initialize stmt->query with NULL, we ecalloc()-ed the memory */
1833 : /* Get performance boost if reporting is switched off */
1834 112 : if (stmt->stmt && query_len && (MyG(report_mode) & MYSQLI_REPORT_INDEX)) {
1835 0 : stmt->query = (char *)emalloc(query_len + 1);
1836 0 : memcpy(stmt->query, query, query_len);
1837 0 : stmt->query[query_len] = '\0';
1838 : }
1839 :
1840 : /* don't join to the previous if because it won't work if mysql_stmt_prepare_fails */
1841 112 : if (!stmt->stmt) {
1842 10 : MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
1843 10 : efree(stmt);
1844 10 : RETURN_FALSE;
1845 : }
1846 :
1847 102 : mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
1848 102 : mysqli_resource->ptr = (void *)stmt;
1849 :
1850 : /* change status */
1851 102 : mysqli_resource->status = MYSQLI_STATUS_VALID;
1852 102 : MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_stmt_class_entry);
1853 : }
1854 : /* }}} */
1855 :
1856 : /* {{{ proto bool mysqli_real_connect(object link [,string hostname [,string username [,string passwd [,string dbname [,int port [,string socket [,int flags]]]]]]]) U
1857 : Open a connection to a mysql server */
1858 : PHP_FUNCTION(mysqli_real_connect)
1859 1018 : {
1860 1018 : mysqli_common_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, TRUE, FALSE);
1861 1018 : }
1862 : /* }}} */
1863 :
1864 : /* {{{ proto bool mysqli_real_query(object link, string query) U
1865 : Binary-safe version of mysql_query() */
1866 : PHP_FUNCTION(mysqli_real_query)
1867 47 : {
1868 : MY_MYSQL *mysql;
1869 : zval *mysql_link;
1870 47 : char *query = NULL;
1871 : unsigned int query_len;
1872 :
1873 47 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os&", &mysql_link, mysqli_link_class_entry,
1874 : &query, &query_len, UG(utf8_conv)) == FAILURE) {
1875 3 : return;
1876 : }
1877 44 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
1878 :
1879 43 : MYSQLI_DISABLE_MQ; /* disable multi statements/queries */
1880 :
1881 43 : if (mysql_real_query(mysql->mysql, query, query_len)) {
1882 7 : MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
1883 7 : RETURN_FALSE;
1884 : }
1885 :
1886 36 : if (!mysql_field_count(mysql->mysql)) {
1887 13 : if (MyG(report_mode) & MYSQLI_REPORT_INDEX) {
1888 0 : php_mysqli_report_index(query, mysqli_server_status(mysql->mysql) TSRMLS_CC);
1889 : }
1890 : }
1891 :
1892 36 : RETURN_TRUE;
1893 : }
1894 : /* }}} */
1895 :
1896 : /* {{{ proto string mysqli_real_escape_string(object link, string escapestr) U
1897 : Escapes special characters in a string for use in a SQL statement, taking into account the current charset of the connection */
1898 2775 : PHP_FUNCTION(mysqli_real_escape_string) {
1899 : MY_MYSQL *mysql;
1900 2775 : zval *mysql_link = NULL;
1901 : char *escapestr, *newstr;
1902 : int escapestr_len, newstr_len;
1903 :
1904 2775 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os&", &mysql_link, mysqli_link_class_entry,
1905 : &escapestr, &escapestr_len, UG(utf8_conv)) == FAILURE) {
1906 7 : return;
1907 : }
1908 2768 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
1909 :
1910 2766 : newstr = safe_emalloc(2, escapestr_len, 1);
1911 2766 : newstr_len = mysql_real_escape_string(mysql->mysql, newstr, escapestr, escapestr_len);
1912 2766 : newstr = erealloc(newstr, newstr_len + 1);
1913 :
1914 2766 : RETURN_UTF8_STRINGL(newstr, newstr_len, ZSTR_AUTOFREE);
1915 : }
1916 : /* }}} */
1917 :
1918 : /* {{{ proto bool mysqli_rollback(object link) U
1919 : Undo actions from current transaction */
1920 : PHP_FUNCTION(mysqli_rollback)
1921 7 : {
1922 : MY_MYSQL *mysql;
1923 : zval *mysql_link;
1924 :
1925 7 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
1926 3 : return;
1927 : }
1928 4 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
1929 :
1930 3 : if (mysql_rollback(mysql->mysql)) {
1931 0 : RETURN_FALSE;
1932 : }
1933 3 : RETURN_TRUE;
1934 : }
1935 : /* }}} */
1936 :
1937 : /* {{{ proto bool mysqli_stmt_send_long_data(object stmt, int param_nr, string data) U
1938 : */
1939 : PHP_FUNCTION(mysqli_stmt_send_long_data)
1940 23 : {
1941 : MY_STMT *stmt;
1942 : zval *mysql_stmt;
1943 : char *data;
1944 : long param_nr;
1945 : int data_len;
1946 :
1947 23 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ols&", &mysql_stmt, mysqli_stmt_class_entry, ¶m_nr,
1948 : &data, &data_len, UG(utf8_conv)) == FAILURE) {
1949 5 : return;
1950 : }
1951 18 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
1952 :
1953 18 : if (param_nr < 0) {
1954 2 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter number");
1955 2 : RETURN_FALSE;
1956 : }
1957 16 : if (mysql_stmt_send_long_data(stmt->stmt, param_nr, data, data_len)) {
1958 1 : RETURN_FALSE;
1959 : }
1960 15 : RETURN_TRUE;
1961 : }
1962 : /* }}} */
1963 :
1964 :
1965 : /* {{{ proto mixed mysqli_stmt_affected_rows(object stmt) U
1966 : Return the number of rows affected in the last query for the given link */
1967 : PHP_FUNCTION(mysqli_stmt_affected_rows)
1968 25 : {
1969 : MY_STMT *stmt;
1970 : zval *mysql_stmt;
1971 : my_ulonglong rc;
1972 :
1973 25 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
1974 2 : return;
1975 : }
1976 23 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
1977 :
1978 21 : rc = mysql_stmt_affected_rows(stmt->stmt);
1979 21 : if (rc == (my_ulonglong) -1) {
1980 5 : RETURN_LONG(-1);
1981 : }
1982 16 : MYSQLI_RETURN_LONG_LONG(rc)
1983 : }
1984 : /* }}} */
1985 :
1986 : /* {{{ proto bool mysqli_stmt_close(object stmt) U
1987 : Close statement */
1988 : PHP_FUNCTION(mysqli_stmt_close)
1989 887 : {
1990 : MY_STMT *stmt;
1991 : zval *mysql_stmt;
1992 :
1993 887 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
1994 2 : return;
1995 : }
1996 885 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
1997 :
1998 882 : mysqli_stmt_close(stmt->stmt, FALSE);
1999 882 : stmt->stmt = NULL;
2000 882 : php_clear_stmt_bind(stmt TSRMLS_CC);
2001 882 : MYSQLI_CLEAR_RESOURCE(&mysql_stmt);
2002 882 : RETURN_TRUE;
2003 : }
2004 : /* }}} */
2005 :
2006 : /* {{{ proto void mysqli_stmt_data_seek(object stmt, int offset) U
2007 : Move internal result pointer */
2008 : PHP_FUNCTION(mysqli_stmt_data_seek)
2009 8 : {
2010 : MY_STMT *stmt;
2011 : zval *mysql_stmt;
2012 : long offset;
2013 :
2014 8 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &mysql_stmt, mysqli_stmt_class_entry, &offset) == FAILURE) {
2015 2 : return;
2016 : }
2017 6 : if (offset < 0) {
2018 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset must be positive");
2019 1 : RETURN_FALSE;
2020 : }
2021 :
2022 5 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
2023 :
2024 3 : mysql_stmt_data_seek(stmt->stmt, offset);
2025 : }
2026 : /* }}} */
2027 :
2028 : /* {{{ proto int mysqli_stmt_field_count(object stmt) U
2029 : Return the number of result columns for the given statement */
2030 : PHP_FUNCTION(mysqli_stmt_field_count)
2031 20 : {
2032 : MY_STMT *stmt;
2033 : zval *mysql_stmt;
2034 :
2035 20 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
2036 2 : return;
2037 : }
2038 18 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
2039 :
2040 15 : RETURN_LONG(mysql_stmt_field_count(stmt->stmt));
2041 : }
2042 : /* }}} */
2043 :
2044 : /* {{{ proto void mysqli_stmt_free_result(object stmt) U
2045 : Free stored result memory for the given statement handle */
2046 : PHP_FUNCTION(mysqli_stmt_free_result)
2047 50 : {
2048 : MY_STMT *stmt;
2049 : zval *mysql_stmt;
2050 :
2051 50 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
2052 2 : return;
2053 : }
2054 :
2055 48 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
2056 :
2057 46 : mysql_stmt_free_result(stmt->stmt);
2058 : }
2059 : /* }}} */
2060 :
2061 : /* {{{ proto mixed mysqli_stmt_insert_id(object stmt) U
2062 : Get the ID generated from the previous INSERT operation */
2063 : PHP_FUNCTION(mysqli_stmt_insert_id)
2064 8 : {
2065 : MY_STMT *stmt;
2066 : my_ulonglong rc;
2067 : zval *mysql_stmt;
2068 :
2069 8 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
2070 1 : return;
2071 : }
2072 7 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
2073 5 : rc = mysql_stmt_insert_id(stmt->stmt);
2074 5 : MYSQLI_RETURN_LONG_LONG(rc)
2075 : }
2076 : /* }}} */
2077 :
2078 : /* {{{ proto int mysqli_stmt_param_count(object stmt) U
2079 : Return the number of parameter for the given statement */
2080 : PHP_FUNCTION(mysqli_stmt_param_count)
2081 10 : {
2082 : MY_STMT *stmt;
2083 : zval *mysql_stmt;
2084 :
2085 10 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
2086 3 : return;
2087 : }
2088 7 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
2089 :
2090 5 : RETURN_LONG(mysql_stmt_param_count(stmt->stmt));
2091 : }
2092 : /* }}} */
2093 :
2094 : /* {{{ proto bool mysqli_stmt_reset(object stmt) U
2095 : reset a prepared statement */
2096 : PHP_FUNCTION(mysqli_stmt_reset)
2097 10 : {
2098 : MY_STMT *stmt;
2099 : zval *mysql_stmt;
2100 :
2101 10 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
2102 3 : return;
2103 : }
2104 :
2105 7 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
2106 :
2107 5 : if (mysql_stmt_reset(stmt->stmt)) {
2108 0 : RETURN_FALSE;
2109 : }
2110 5 : RETURN_TRUE;
2111 : }
2112 : /* }}} */
2113 :
2114 : /* {{{ proto mixed mysqli_stmt_num_rows(object stmt) U
2115 : Return the number of rows in statements result set */
2116 : PHP_FUNCTION(mysqli_stmt_num_rows)
2117 24 : {
2118 : MY_STMT *stmt;
2119 : zval *mysql_stmt;
2120 : my_ulonglong rc;
2121 :
2122 24 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
2123 2 : return;
2124 : }
2125 :
2126 22 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
2127 :
2128 21 : rc = mysql_stmt_num_rows(stmt->stmt);
2129 21 : MYSQLI_RETURN_LONG_LONG(rc)
2130 : }
2131 : /* }}} */
2132 :
2133 : /* {{{ proto bool mysqli_select_db(object link, string dbname) U
2134 : Select a MySQL database */
2135 : PHP_FUNCTION(mysqli_select_db)
2136 49 : {
2137 : MY_MYSQL *mysql;
2138 : zval *mysql_link;
2139 : char *dbname;
2140 : int dbname_len;
2141 :
2142 49 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os&", &mysql_link, mysqli_link_class_entry,
2143 : &dbname, &dbname_len, UG(utf8_conv)) == FAILURE) {
2144 3 : return;
2145 : }
2146 46 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
2147 :
2148 45 : if (mysql_select_db(mysql->mysql, dbname)) {
2149 7 : MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
2150 7 : RETURN_FALSE;
2151 : }
2152 38 : RETURN_TRUE;
2153 : }
2154 : /* }}} */
2155 :
2156 : /* {{{ proto string mysqli_sqlstate(object link) U
2157 : Returns the SQLSTATE error from previous MySQL operation */
2158 : PHP_FUNCTION(mysqli_sqlstate)
2159 10 : {
2160 : MY_MYSQL *mysql;
2161 : zval *mysql_link;
2162 :
2163 10 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
2164 3 : return;
2165 : }
2166 7 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
2167 6 : RETURN_UTF8_STRING((char *)mysql_sqlstate(mysql->mysql), ZSTR_DUPLICATE);
2168 : }
2169 : /* }}} */
2170 :
2171 : /* {{{ proto bool mysqli_ssl_set(object link ,string key ,string cert ,string ca ,string capath ,string cipher]) U
2172 : */
2173 : #if !defined(MYSQLI_USE_MYSQLND)
2174 : PHP_FUNCTION(mysqli_ssl_set)
2175 : {
2176 : MY_MYSQL *mysql;
2177 : zval *mysql_link;
2178 : char *ssl_parm[5];
2179 : int ssl_parm_len[5], i;
2180 :
2181 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os&s&s&s&s&", &mysql_link, mysqli_link_class_entry,
2182 : &ssl_parm[0], &ssl_parm_len[0], UG(utf8_conv), &ssl_parm[1], &ssl_parm_len[1], UG(utf8_conv),
2183 : &ssl_parm[2], &ssl_parm_len[2], UG(utf8_conv), &ssl_parm[3], &ssl_parm_len[3], UG(utf8_conv),
2184 : &ssl_parm[4], &ssl_parm_len[4], UG(utf8_conv)) == FAILURE) {
2185 : return;
2186 : }
2187 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
2188 :
2189 : for (i = 0; i < 5; i++) {
2190 : if (!ssl_parm_len[i]) {
2191 : ssl_parm[i] = NULL;
2192 : }
2193 : }
2194 :
2195 : mysql_ssl_set(mysql->mysql, ssl_parm[0], ssl_parm[1], ssl_parm[2], ssl_parm[3], ssl_parm[4]);
2196 :
2197 : RETURN_TRUE;
2198 : }
2199 : #endif
2200 : /* }}} */
2201 :
2202 : /* {{{ proto mixed mysqli_stat(object link) U
2203 : Get current system status */
2204 : PHP_FUNCTION(mysqli_stat)
2205 7 : {
2206 : MY_MYSQL *mysql;
2207 : zval *mysql_link;
2208 : char *stat;
2209 : #if defined(MYSQLI_USE_MYSQLND)
2210 : uint stat_len;
2211 : #endif
2212 :
2213 7 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
2214 3 : return;
2215 : }
2216 4 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
2217 :
2218 : #if !defined(MYSQLI_USE_MYSQLND)
2219 : if ((stat = (char *)mysql_stat(mysql->mysql)))
2220 : {
2221 : RETURN_UTF8_STRING(stat, ZSTR_DUPLICATE);
2222 : #else
2223 3 : if (mysqlnd_stat(mysql->mysql, &stat, &stat_len) == PASS)
2224 : {
2225 3 : RETURN_UTF8_STRINGL(stat, stat_len, ZSTR_AUTOFREE);
2226 : #endif
2227 : } else {
2228 0 : RETURN_FALSE;
2229 : }
2230 : }
2231 :
2232 : /* }}} */
2233 :
2234 : /* {{{ proto bool mysqli_refresh(object link, long options)
2235 : Flush tables or caches, or reset replication server information */
2236 : PHP_FUNCTION(mysqli_refresh)
2237 0 : {
2238 : MY_MYSQL *mysql;
2239 0 : zval *mysql_link = NULL;
2240 : long options;
2241 :
2242 0 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &mysql_link, mysqli_link_class_entry, &options) == FAILURE) {
2243 0 : return;
2244 : }
2245 0 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_INITIALIZED);
2246 : #ifdef MYSQLI_USE_MYSQLND
2247 0 : RETURN_BOOL(!mysql_refresh(mysql->mysql, (uint8_t) options));
2248 : #else
2249 : RETURN_BOOL(!mysql_refresh(mysql->mysql, options));
2250 : #endif
2251 : }
2252 : /* }}} */
2253 :
2254 : /* {{{ proto int mysqli_stmt_attr_set(object stmt, long attr, long mode) U
2255 : */
2256 : PHP_FUNCTION(mysqli_stmt_attr_set)
2257 1115 : {
2258 : MY_STMT *stmt;
2259 : zval *mysql_stmt;
2260 : long mode_in;
2261 : ulong mode;
2262 : ulong attr;
2263 :
2264 1115 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll", &mysql_stmt, mysqli_stmt_class_entry, &attr, &mode_in) == FAILURE) {
2265 4 : return;
2266 : }
2267 1111 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
2268 :
2269 1110 : if (mode_in < 0) {
2270 1 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "mode should be non-negative, %ld passed", mode_in);
2271 1 : RETURN_FALSE;
2272 : }
2273 :
2274 1109 : mode = mode_in;
2275 : #if !defined(MYSQLI_USE_MYSQLND)
2276 : if (FALSE == mysql_stmt_attr_set(stmt->stmt, attr, (void *)&mode)) {
2277 : #else
2278 1109 : if (FAIL == mysql_stmt_attr_set(stmt->stmt, attr, (void *)&mode)) {
2279 : #endif
2280 1100 : RETURN_FALSE;
2281 : }
2282 9 : RETURN_TRUE;
2283 : }
2284 : /* }}} */
2285 :
2286 : /* {{{ proto int mysqli_stmt_attr_get(object stmt, long attr) U
2287 : */
2288 : PHP_FUNCTION(mysqli_stmt_attr_get)
2289 9 : {
2290 : MY_STMT *stmt;
2291 : zval *mysql_stmt;
2292 : #if !defined(MYSQLI_USE_MYSQLND) && MYSQL_VERSION_ID > 50099
2293 : my_bool value;
2294 : #else
2295 9 : ulong value = 0;
2296 : #endif
2297 : ulong attr;
2298 : int rc;
2299 :
2300 9 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &mysql_stmt, mysqli_stmt_class_entry, &attr) == FAILURE) {
2301 4 : return;
2302 : }
2303 5 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
2304 :
2305 3 : if ((rc = mysql_stmt_attr_get(stmt->stmt, attr, &value))) {
2306 1 : RETURN_FALSE;
2307 : }
2308 2 : RETURN_LONG((long)value);
2309 : }
2310 : /* }}} */
2311 :
2312 : /* {{{ proto int mysqli_stmt_errno(object stmt) U
2313 : */
2314 : PHP_FUNCTION(mysqli_stmt_errno)
2315 11 : {
2316 : MY_STMT *stmt;
2317 : zval *mysql_stmt;
2318 :
2319 11 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
2320 2 : return;
2321 : }
2322 9 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_INITIALIZED);
2323 :
2324 8 : RETURN_LONG(mysql_stmt_errno(stmt->stmt));
2325 : }
2326 : /* }}} */
2327 :
2328 : /* {{{ proto string mysqli_stmt_error(object stmt) U
2329 : */
2330 : PHP_FUNCTION(mysqli_stmt_error)
2331 10 : {
2332 : MY_STMT *stmt;
2333 : zval *mysql_stmt;
2334 :
2335 10 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
2336 2 : return;
2337 : }
2338 8 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_INITIALIZED);
2339 :
2340 7 : RETURN_UTF8_STRING((char *)mysql_stmt_error(stmt->stmt), ZSTR_DUPLICATE);
2341 : }
2342 : /* }}} */
2343 :
2344 : /* {{{ proto mixed mysqli_stmt_init(object link) U
2345 : Initialize statement object
2346 : */
2347 : PHP_FUNCTION(mysqli_stmt_init)
2348 811 : {
2349 : MY_MYSQL *mysql;
2350 : MY_STMT *stmt;
2351 : zval *mysql_link;
2352 : MYSQLI_RESOURCE *mysqli_resource;
2353 :
2354 811 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",&mysql_link, mysqli_link_class_entry) == FAILURE) {
2355 3 : return;
2356 : }
2357 808 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
2358 :
2359 807 : stmt = (MY_STMT *)ecalloc(1,sizeof(MY_STMT));
2360 :
2361 807 : if (!(stmt->stmt = mysql_stmt_init(mysql->mysql))) {
2362 0 : efree(stmt);
2363 0 : RETURN_FALSE;
2364 : }
2365 :
2366 807 : mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
2367 807 : mysqli_resource->status = MYSQLI_STATUS_INITIALIZED;
2368 807 : mysqli_resource->ptr = (void *)stmt;
2369 807 : MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_stmt_class_entry);
2370 : }
2371 : /* }}} */
2372 :
2373 : /* {{{ proto bool mysqli_stmt_prepare(object stmt, string query) U
2374 : prepare server side statement with query
2375 : */
2376 : PHP_FUNCTION(mysqli_stmt_prepare)
2377 3240 : {
2378 : MY_STMT *stmt;
2379 : zval *mysql_stmt;
2380 : char *query;
2381 : int query_len;
2382 :
2383 3240 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os&", &mysql_stmt, mysqli_stmt_class_entry,
2384 : &query, &query_len, UG(utf8_conv)) == FAILURE) {
2385 5 : return;
2386 : }
2387 3235 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_INITIALIZED);
2388 :
2389 3233 : if (mysql_stmt_prepare(stmt->stmt, query, query_len)) {
2390 10 : MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
2391 10 : RETURN_FALSE;
2392 : }
2393 : /* change status */
2394 3223 : MYSQLI_SET_STATUS(&mysql_stmt, MYSQLI_STATUS_VALID);
2395 3223 : RETURN_TRUE;
2396 : }
2397 : /* }}} */
2398 :
2399 : /* {{{ proto mixed mysqli_stmt_result_metadata(object stmt) U
2400 : return result set from statement */
2401 : PHP_FUNCTION(mysqli_stmt_result_metadata)
2402 220 : {
2403 : MY_STMT *stmt;
2404 : MYSQL_RES *result;
2405 : zval *mysql_stmt;
2406 : MYSQLI_RESOURCE *mysqli_resource;
2407 :
2408 220 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
2409 3 : return;
2410 : }
2411 217 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
2412 :
2413 215 : if (!(result = mysql_stmt_result_metadata(stmt->stmt))){
2414 0 : MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
2415 0 : RETURN_FALSE;
2416 : }
2417 :
2418 215 : mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
2419 215 : mysqli_resource->ptr = (void *)result;
2420 215 : mysqli_resource->status = MYSQLI_STATUS_VALID;
2421 215 : MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_result_class_entry);
2422 : }
2423 : /* }}} */
2424 :
2425 : /* {{{ proto bool mysqli_stmt_store_result(stmt) U
2426 : */
2427 : PHP_FUNCTION(mysqli_stmt_store_result)
2428 58 : {
2429 : MY_STMT *stmt;
2430 : zval *mysql_stmt;
2431 :
2432 58 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
2433 2 : return;
2434 : }
2435 56 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
2436 :
2437 : #if !defined(MYSQLI_USE_MYSQLND)
2438 : {
2439 : /*
2440 : If the user wants to store the data and we have BLOBs/TEXTs we try to allocate
2441 : not the maximal length of the type (which is 16MB even for LONGBLOB) but
2442 : the maximal length of the field in the result set. If he/she has quite big
2443 : BLOB/TEXT columns after calling store_result() the memory usage of PHP will
2444 : double - but this is a known problem of the simple MySQL API ;)
2445 : */
2446 : int i = 0;
2447 :
2448 : for (i = mysql_stmt_field_count(stmt->stmt) - 1; i >=0; --i) {
2449 : if (stmt->stmt->fields && (stmt->stmt->fields[i].type == MYSQL_TYPE_BLOB ||
2450 : stmt->stmt->fields[i].type == MYSQL_TYPE_MEDIUM_BLOB ||
2451 : stmt->stmt->fields[i].type == MYSQL_TYPE_LONG_BLOB ||
2452 : stmt->stmt->fields[i].type == MYSQL_TYPE_GEOMETRY))
2453 : {
2454 : my_bool tmp=1;
2455 : mysql_stmt_attr_set(stmt->stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &tmp);
2456 : break;
2457 : }
2458 : }
2459 : }
2460 : #endif
2461 :
2462 53 : if (mysql_stmt_store_result(stmt->stmt)){
2463 3 : MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
2464 3 : RETURN_FALSE;
2465 : }
2466 50 : RETURN_TRUE;
2467 : }
2468 : /* }}} */
2469 :
2470 : /* {{{ proto string mysqli_stmt_sqlstate(object stmt) U
2471 : */
2472 : PHP_FUNCTION(mysqli_stmt_sqlstate)
2473 8 : {
2474 : MY_STMT *stmt;
2475 : zval *mysql_stmt;
2476 :
2477 8 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
2478 3 : return;
2479 : }
2480 5 : MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt", MYSQLI_STATUS_VALID);
2481 :
2482 3 : RETURN_UTF8_STRING((char *)mysql_stmt_sqlstate(stmt->stmt), ZSTR_DUPLICATE);
2483 : }
2484 : /* }}} */
2485 :
2486 : /* {{{ proto object mysqli_store_result(object link) U
2487 : Buffer result set on client */
2488 : PHP_FUNCTION(mysqli_store_result)
2489 50 : {
2490 : MY_MYSQL *mysql;
2491 : MYSQL_RES *result;
2492 : zval *mysql_link;
2493 : MYSQLI_RESOURCE *mysqli_resource;
2494 :
2495 50 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
2496 2 : return;
2497 : }
2498 48 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
2499 :
2500 47 : if (!(result = mysql_store_result(mysql->mysql))) {
2501 10 : MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
2502 10 : RETURN_FALSE;
2503 : }
2504 37 : if (MyG(report_mode) & MYSQLI_REPORT_INDEX) {
2505 0 : php_mysqli_report_index("from previous query", mysqli_server_status(mysql->mysql) TSRMLS_CC);
2506 : }
2507 :
2508 37 : mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
2509 37 : mysqli_resource->ptr = (void *)result;
2510 37 : mysqli_resource->status = MYSQLI_STATUS_VALID;
2511 37 : MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_result_class_entry);
2512 : }
2513 : /* }}} */
2514 :
2515 :
2516 : /* {{{ proto int mysqli_thread_id(object link) U
2517 : Return the current thread ID */
2518 : PHP_FUNCTION(mysqli_thread_id)
2519 70 : {
2520 : MY_MYSQL *mysql;
2521 : zval *mysql_link;
2522 :
2523 70 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
2524 2 : return;
2525 : }
2526 68 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
2527 :
2528 67 : RETURN_LONG((long) mysql_thread_id(mysql->mysql));
2529 : }
2530 : /* }}} */
2531 :
2532 : /* {{{ proto bool mysqli_thread_safe(void) U
2533 : Return whether thread safety is given or not */
2534 : PHP_FUNCTION(mysqli_thread_safe)
2535 2 : {
2536 2 : RETURN_BOOL(mysql_thread_safe());
2537 : }
2538 : /* }}} */
2539 :
2540 : /* {{{ proto mixed mysqli_use_result(object link) U
2541 : Directly retrieve query results - do not buffer results on client side */
2542 : PHP_FUNCTION(mysqli_use_result)
2543 21 : {
2544 : MY_MYSQL *mysql;
2545 : MYSQL_RES *result;
2546 : zval *mysql_link;
2547 : MYSQLI_RESOURCE *mysqli_resource;
2548 :
2549 21 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
2550 2 : return;
2551 : }
2552 19 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
2553 :
2554 18 : if (!(result = mysql_use_result(mysql->mysql))) {
2555 3 : MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
2556 3 : RETURN_FALSE;
2557 : }
2558 :
2559 15 : if (MyG(report_mode) & MYSQLI_REPORT_INDEX) {
2560 0 : php_mysqli_report_index("from previous query", mysqli_server_status(mysql->mysql) TSRMLS_CC);
2561 : }
2562 15 : mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
2563 15 : mysqli_resource->ptr = (void *)result;
2564 15 : mysqli_resource->status = MYSQLI_STATUS_VALID;
2565 15 : MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_result_class_entry);
2566 : }
2567 : /* }}} */
2568 :
2569 : /* {{{ proto int mysqli_warning_count (object link) U
2570 : Return number of warnings from the last query for the given link */
2571 : PHP_FUNCTION(mysqli_warning_count)
2572 10 : {
2573 : MY_MYSQL *mysql;
2574 : zval *mysql_link;
2575 :
2576 10 : if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
2577 3 : return;
2578 : }
2579 7 : MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
2580 :
2581 6 : RETURN_LONG(mysql_warning_count(mysql->mysql));
2582 : }
2583 : /* }}} */
2584 :
2585 : /*
2586 : * Local variables:
2587 : * tab-width: 4
2588 : * c-basic-offset: 4
2589 : * End:
2590 : * vim600: noet sw=4 ts=4 fdm=marker
2591 : * vim<600: noet sw=4 ts=4
2592 : */
|