PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/mysqli - mysqli_api.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 665 717 92.7 %
Date: 2014-07-21 Functions: 79 83 95.2 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Tue, 22 Jul 2014 01:33:12 +0000 (11 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.