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