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.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 469 521 90.0 %
Date: 2014-04-16 Functions: 27 30 90.0 %
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 "ext/standard/info.h"
      32             : #include "ext/standard/php_string.h"
      33             : #include "php_mysqli.h"
      34             : #include "php_mysqli_structs.h"
      35             : #include "mysqli_priv.h"
      36             : #include "zend_exceptions.h"
      37             : #include "zend_interfaces.h"
      38             : 
      39             : ZEND_DECLARE_MODULE_GLOBALS(mysqli)
      40             : static PHP_GINIT_FUNCTION(mysqli);
      41             : 
      42             : #define MYSQLI_ADD_PROPERTIES(a,b) \
      43             : { \
      44             :         int i = 0; \
      45             :         while (b[i].pname != NULL) { \
      46             :                 mysqli_add_property((a), (b)[i].pname, (b)[i].pname_length, \
      47             :                                                         (mysqli_read_t)(b)[i].r_func, (mysqli_write_t)(b)[i].w_func TSRMLS_CC); \
      48             :                 i++; \
      49             :         }\
      50             : }
      51             : 
      52             : #define MYSQLI_ADD_PROPERTIES_INFO(a,b) \
      53             : { \
      54             :         int i = 0; \
      55             :         while (b[i].name != NULL) { \
      56             :                 zend_declare_property_null((a), (b)[i].name, (b)[i].name_length, ZEND_ACC_PUBLIC TSRMLS_CC); \
      57             :                 i++; \
      58             :         }\
      59             : }
      60             : 
      61             : 
      62             : 
      63             : static zend_object_handlers mysqli_object_handlers;
      64             : static HashTable classes;
      65             : static HashTable mysqli_driver_properties;
      66             : static HashTable mysqli_link_properties;
      67             : static HashTable mysqli_result_properties;
      68             : static HashTable mysqli_stmt_properties;
      69             : static HashTable mysqli_warning_properties;
      70             : 
      71             : zend_class_entry *mysqli_link_class_entry;
      72             : zend_class_entry *mysqli_stmt_class_entry;
      73             : zend_class_entry *mysqli_result_class_entry;
      74             : zend_class_entry *mysqli_driver_class_entry;
      75             : zend_class_entry *mysqli_warning_class_entry;
      76             : zend_class_entry *mysqli_exception_class_entry;
      77             : 
      78             : 
      79             : typedef int (*mysqli_read_t)(mysqli_object *obj, zval **retval TSRMLS_DC);
      80             : typedef int (*mysqli_write_t)(mysqli_object *obj, zval *newval TSRMLS_DC);
      81             : 
      82             : typedef struct _mysqli_prop_handler {
      83             :         char *name;
      84             :         size_t name_len;
      85             :         mysqli_read_t read_func;
      86             :         mysqli_write_t write_func;
      87             : } mysqli_prop_handler;
      88             : 
      89             : static int le_pmysqli;
      90             : 
      91             : 
      92             : /* Destructor for mysqli entries in free_links/used_links */
      93          35 : void php_mysqli_dtor_p_elements(void *data)
      94             : {
      95          35 :         MYSQL *mysql = (MYSQL *) data;
      96             :         TSRMLS_FETCH();
      97          35 :         mysqli_close(mysql, MYSQLI_CLOSE_IMPLICIT);
      98          35 : }
      99             : 
     100             : 
     101          14 : ZEND_RSRC_DTOR_FUNC(php_mysqli_dtor)
     102             : {
     103          14 :         if (rsrc->ptr) {
     104          14 :                 mysqli_plist_entry *plist = (mysqli_plist_entry *) rsrc->ptr;
     105          14 :                 zend_ptr_stack_clean(&plist->free_links, php_mysqli_dtor_p_elements, 0);
     106          14 :                 zend_ptr_stack_destroy(&plist->free_links);
     107          14 :                 free(plist);
     108             :         }
     109          14 : }
     110             : 
     111             : 
     112         174 : int php_le_pmysqli(void)
     113             : {
     114         174 :         return le_pmysqli;
     115             : }
     116             : 
     117             : #ifndef MYSQLI_USE_MYSQLND
     118             : /* {{{ php_free_stmt_bind_buffer */
     119             : void php_free_stmt_bind_buffer(BIND_BUFFER bbuf, int type)
     120             : {
     121             :         unsigned int i;
     122             : 
     123             :         if (!bbuf.var_cnt) {
     124             :                 return;
     125             :         }
     126             : 
     127             :         for (i=0; i < bbuf.var_cnt; i++) {
     128             : 
     129             :                 /* free temporary bind buffer */
     130             :                 if (type == FETCH_RESULT && bbuf.buf[i].val) {
     131             :                         efree(bbuf.buf[i].val);
     132             :                 }
     133             : 
     134             :                 if (bbuf.vars[i]) {
     135             :                         zval_ptr_dtor(&bbuf.vars[i]);
     136             :                 }
     137             :         }
     138             : 
     139             :         if (bbuf.vars) {
     140             :                 efree(bbuf.vars);
     141             :         }
     142             : 
     143             :         /*
     144             :           Don't free bbuf.is_null for FETCH_RESULT since we have allocated
     145             :           is_null and buf in one block so we free only buf, which is the beginning
     146             :           of the block. When FETCH_SIMPLE then buf wasn't allocated together with
     147             :           buf and we have to free it.
     148             :         */
     149             :         if (type == FETCH_RESULT) {
     150             :                 efree(bbuf.buf);
     151             :         } else if (type == FETCH_SIMPLE){
     152             :                 efree(bbuf.is_null);
     153             :         }
     154             : 
     155             :         bbuf.var_cnt = 0;
     156             : }
     157             : /* }}} */
     158             : #endif
     159             : 
     160             : /* {{{ php_clear_stmt_bind */
     161         944 : void php_clear_stmt_bind(MY_STMT *stmt TSRMLS_DC)
     162             : {
     163         944 :         if (stmt->stmt) {
     164          32 :                 if (mysqli_stmt_close(stmt->stmt, TRUE)) {
     165           0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error occurred while closing statement");
     166           0 :                         return;
     167             :                 }
     168             :         }
     169             : 
     170             :         /*
     171             :           mysqlnd keeps track of the binding and has freed its
     172             :           structures in stmt_close() above
     173             :         */
     174             : #ifndef MYSQLI_USE_MYSQLND
     175             :         /* Clean param bind */
     176             :         php_free_stmt_bind_buffer(stmt->param, FETCH_SIMPLE);
     177             :         /* Clean output bind */
     178             :         php_free_stmt_bind_buffer(stmt->result, FETCH_RESULT);
     179             : 
     180             :         if (stmt->link_handle) {
     181             :             zend_objects_store_del_ref_by_handle(stmt->link_handle TSRMLS_CC);
     182             :         }
     183             : #endif
     184         944 :         if (stmt->query) {
     185           0 :                 efree(stmt->query);
     186             :         }
     187         944 :         efree(stmt);
     188             : }
     189             : /* }}} */
     190             : 
     191             : /* {{{ php_clear_mysql */
     192        1427 : void php_clear_mysql(MY_MYSQL *mysql) {
     193        1427 :         if (mysql->hash_key) {
     194          85 :                 efree(mysql->hash_key);
     195          85 :                 mysql->hash_key = NULL;
     196             :         }
     197        1427 :         if (mysql->li_read) {
     198           0 :                 zval_ptr_dtor(&(mysql->li_read));
     199           0 :                 mysql->li_read = NULL;
     200             :         }
     201        1427 : }
     202             : /* }}} */
     203             : 
     204             : /* {{{ mysqli_objects_free_storage
     205             :  */
     206        5744 : static void mysqli_objects_free_storage(void *object TSRMLS_DC)
     207             : {
     208        5744 :         zend_object *zo = (zend_object *)object;
     209        5744 :         mysqli_object   *intern = (mysqli_object *)zo;
     210        5744 :         MYSQLI_RESOURCE *my_res = (MYSQLI_RESOURCE *)intern->ptr;
     211             : 
     212        5744 :         my_efree(my_res);
     213        5744 :         zend_object_std_dtor(&intern->zo TSRMLS_CC);
     214        5744 :         efree(intern);
     215        5744 : }
     216             : /* }}} */
     217             : 
     218             : /* mysqli_link_free_storage partly doubles the work of PHP_FUNCTION(mysqli_close) */
     219             : 
     220             : /* {{{ mysqli_link_free_storage
     221             :  */
     222        1228 : static void mysqli_link_free_storage(void *object TSRMLS_DC)
     223             : {
     224        1228 :         zend_object *zo = (zend_object *)object;
     225        1228 :         mysqli_object   *intern = (mysqli_object *)zo;
     226        1228 :         MYSQLI_RESOURCE *my_res = (MYSQLI_RESOURCE *)intern->ptr;
     227             : 
     228        1228 :         if (my_res && my_res->ptr) {
     229         187 :                 MY_MYSQL *mysql = (MY_MYSQL *)my_res->ptr;
     230         187 :                 if (mysql->mysql) {
     231         187 :                         php_mysqli_close(mysql, MYSQLI_CLOSE_EXPLICIT, my_res->status TSRMLS_CC);
     232             :                 }
     233         187 :                 php_clear_mysql(mysql);
     234         187 :                 efree(mysql);
     235         187 :                 my_res->status = MYSQLI_STATUS_UNKNOWN;
     236             :         }
     237        1228 :         mysqli_objects_free_storage(object TSRMLS_CC);
     238        1228 : }
     239             : /* }}} */
     240             : 
     241             : /* {{{ mysql_driver_free_storage */
     242        1162 : static void mysqli_driver_free_storage(void *object TSRMLS_DC)
     243             : {
     244        1162 :         mysqli_objects_free_storage(object TSRMLS_CC);
     245        1162 : }
     246             : /* }}} */
     247             : 
     248             : /* {{{ mysqli_stmt_free_storage
     249             :  */
     250         947 : static void mysqli_stmt_free_storage(void *object TSRMLS_DC)
     251             : {
     252         947 :         zend_object *zo = (zend_object *)object;
     253         947 :         mysqli_object   *intern = (mysqli_object *)zo;
     254         947 :         MYSQLI_RESOURCE *my_res = (MYSQLI_RESOURCE *)intern->ptr;
     255             : 
     256         947 :         if (my_res && my_res->ptr) {
     257          32 :                 MY_STMT *stmt = (MY_STMT *)my_res->ptr;
     258          32 :                 php_clear_stmt_bind(stmt TSRMLS_CC);
     259             :         }
     260         947 :         mysqli_objects_free_storage(object TSRMLS_CC);
     261         947 : }
     262             : /* }}} */
     263             : 
     264             : /* {{{ mysqli_result_free_storage
     265             :  */
     266        2401 : static void mysqli_result_free_storage(void *object TSRMLS_DC)
     267             : {
     268        2401 :         zend_object *zo = (zend_object *)object;
     269        2401 :         mysqli_object   *intern = (mysqli_object *)zo;
     270        2401 :         MYSQLI_RESOURCE *my_res = (MYSQLI_RESOURCE *)intern->ptr;
     271             : 
     272        2401 :         if (my_res && my_res->ptr) {
     273        1136 :                 mysql_free_result(my_res->ptr);
     274             :         }
     275        2401 :         mysqli_objects_free_storage(object TSRMLS_CC);
     276        2401 : }
     277             : /* }}} */
     278             : 
     279             : /* {{{ mysqli_warning_free_storage
     280             :  */
     281           6 : static void mysqli_warning_free_storage(void *object TSRMLS_DC)
     282             : {
     283           6 :         zend_object *zo = (zend_object *)object;
     284           6 :         mysqli_object   *intern = (mysqli_object *)zo;
     285           6 :         MYSQLI_RESOURCE *my_res = (MYSQLI_RESOURCE *)intern->ptr;
     286             : 
     287           6 :         if (my_res && my_res->ptr) {
     288           5 :                 php_clear_warnings((MYSQLI_WARNING *)my_res->info);
     289           5 :                 my_res->ptr = NULL;
     290             :         }
     291           6 :         mysqli_objects_free_storage(object TSRMLS_CC);
     292           6 : }
     293             : /* }}} */
     294             : 
     295             : /* {{{ mysqli_read_na */
     296           0 : static int mysqli_read_na(mysqli_object *obj, zval **retval TSRMLS_DC)
     297             : {
     298           0 :         *retval = NULL;
     299           0 :         php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot read property");
     300           0 :         return FAILURE;
     301             : }
     302             : /* }}} */
     303             : 
     304             : /* {{{ mysqli_write_na */
     305           0 : static int mysqli_write_na(mysqli_object *obj, zval *newval TSRMLS_DC)
     306             : {
     307           0 :         php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot write property");
     308           0 :         return FAILURE;
     309             : }
     310             : /* }}} */
     311             : 
     312             : #ifndef Z_ADDREF_P
     313             : /* PHP 5.2, old GC */
     314             : #define Z_ADDREF_P(pz)                          (++(pz)->refcount)
     315             : #define Z_REFCOUNT_P(pz)                        ((pz)->refcount)
     316             : #define Z_SET_REFCOUNT_P(pz, rc)        ((pz)->refcount = rc)
     317             : #endif
     318             : 
     319             : 
     320             : /* {{{ mysqli_read_property */
     321         794 : zval *mysqli_read_property(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC)
     322             : {
     323             :         zval tmp_member;
     324             :         zval *retval;
     325             :         mysqli_object *obj;
     326             :         mysqli_prop_handler *hnd;
     327             :         int ret;
     328             : 
     329         794 :         ret = FAILURE;
     330         794 :         obj = (mysqli_object *)zend_objects_get_address(object TSRMLS_CC);
     331             : 
     332         794 :         if (member->type != IS_STRING) {
     333           0 :                 tmp_member = *member;
     334             :                 zval_copy_ctor(&tmp_member);
     335           0 :                 convert_to_string(&tmp_member);
     336           0 :                 member = &tmp_member;
     337             :         }
     338             : 
     339         794 :         if (obj->prop_handler != NULL) {
     340         794 :                 ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
     341             :         }
     342             : 
     343         794 :         if (ret == SUCCESS) {
     344         779 :                 ret = hnd->read_func(obj, &retval TSRMLS_CC);
     345         779 :                 if (ret == SUCCESS) {
     346             :                         /* ensure we're creating a temporary variable */
     347         777 :                         Z_SET_REFCOUNT_P(retval, 0);
     348             :                 } else {
     349           2 :                         retval = EG(uninitialized_zval_ptr);
     350             :                 }
     351             :         } else {
     352          15 :                 zend_object_handlers * std_hnd = zend_get_std_object_handlers();
     353          15 :                 retval = std_hnd->read_property(object, member, type, key TSRMLS_CC);
     354             :         }
     355             : 
     356         794 :         if (member == &tmp_member) {
     357             :                 zval_dtor(member);
     358             :         }
     359         794 :         return(retval);
     360             : }
     361             : /* }}} */
     362             : 
     363             : /* {{{ mysqli_write_property */
     364          15 : void mysqli_write_property(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC)
     365             : {
     366             :         zval tmp_member;
     367             :         mysqli_object *obj;
     368             :         mysqli_prop_handler *hnd;
     369             :         int ret;
     370             : 
     371          15 :         if (member->type != IS_STRING) {
     372           0 :                 tmp_member = *member;
     373             :                 zval_copy_ctor(&tmp_member);
     374           0 :                 convert_to_string(&tmp_member);
     375           0 :                 member = &tmp_member;
     376             :         }
     377             : 
     378          15 :         ret = FAILURE;
     379          15 :         obj = (mysqli_object *)zend_objects_get_address(object TSRMLS_CC);
     380             : 
     381          15 :         if (obj->prop_handler != NULL) {
     382          15 :                 ret = zend_hash_find((HashTable *)obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
     383             :         }
     384          15 :         if (ret == SUCCESS) {
     385           8 :                 hnd->write_func(obj, value TSRMLS_CC);
     386          24 :                 if (! PZVAL_IS_REF(value) && Z_REFCOUNT_P(value) == 0) {
     387           0 :                         Z_ADDREF_P(value);
     388           0 :                         zval_ptr_dtor(&value);
     389             :                 }
     390             :         } else {
     391           7 :                 zend_object_handlers * std_hnd = zend_get_std_object_handlers();
     392           7 :                 std_hnd->write_property(object, member, value, key TSRMLS_CC);
     393             :         }
     394             : 
     395          15 :         if (member == &tmp_member) {
     396             :                 zval_dtor(member);
     397             :         }
     398          15 : }
     399             : /* }}} */
     400             : 
     401             : /* {{{ void mysqli_add_property(HashTable *h, char *pname, mysqli_read_t r_func, mysqli_write_t w_func TSRMLS_DC) */
     402      909837 : void mysqli_add_property(HashTable *h, const char *pname, size_t pname_len, mysqli_read_t r_func, mysqli_write_t w_func TSRMLS_DC) {
     403             :         mysqli_prop_handler             p;
     404             : 
     405      909837 :         p.name = (char*) pname;
     406      909837 :         p.name_len = pname_len;
     407      909837 :         p.read_func = (r_func) ? r_func : mysqli_read_na;
     408      909837 :         p.write_func = (w_func) ? w_func : mysqli_write_na;
     409      909837 :         zend_hash_add(h, pname, pname_len + 1, &p, sizeof(mysqli_prop_handler), NULL);
     410      909837 : }
     411             : /* }}} */
     412             : 
     413           1 : static int mysqli_object_has_property(zval *object, zval *member, int has_set_exists, const zend_literal *key TSRMLS_DC) /* {{{ */
     414             : {
     415           1 :         mysqli_object *obj = (mysqli_object *)zend_objects_get_address(object TSRMLS_CC);
     416             :         mysqli_prop_handler     p;
     417           1 :         int ret = 0;
     418             : 
     419           1 :         if (zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member) + 1, (void **)&p) == SUCCESS) {
     420           0 :                 switch (has_set_exists) {
     421             :                         case 2:
     422           0 :                                 ret = 1;
     423           0 :                                 break;
     424             :                         case 1: {
     425           0 :                                 zval *value = mysqli_read_property(object, member, BP_VAR_IS, key TSRMLS_CC);
     426           0 :                                 if (value != EG(uninitialized_zval_ptr)) {
     427           0 :                                         convert_to_boolean(value);
     428           0 :                                         ret = Z_BVAL_P(value)? 1:0;
     429             :                                         /* refcount is 0 */
     430           0 :                                         Z_ADDREF_P(value);
     431           0 :                                         zval_ptr_dtor(&value);
     432             :                                 }
     433           0 :                                 break;
     434             :                         }
     435             :                         case 0:{
     436           0 :                                 zval *value = mysqli_read_property(object, member, BP_VAR_IS, key TSRMLS_CC);
     437           0 :                                 if (value != EG(uninitialized_zval_ptr)) {
     438           0 :                                         ret = Z_TYPE_P(value) != IS_NULL? 1:0;
     439             :                                         /* refcount is 0 */
     440           0 :                                         Z_ADDREF_P(value);
     441           0 :                                         zval_ptr_dtor(&value);
     442             :                                 }
     443           0 :                                 break;
     444             :                         }
     445             :                         default:
     446           0 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid value for has_set_exists");
     447             :                 }
     448             :         } else {
     449           1 :                 zend_object_handlers * std_hnd = zend_get_std_object_handlers();
     450           1 :                 ret = std_hnd->has_property(object, member, has_set_exists, key TSRMLS_CC);
     451             :         }
     452           1 :         return ret;
     453             : } /* }}} */
     454             : 
     455             : 
     456             : #if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3
     457           6 : HashTable * mysqli_object_get_debug_info(zval *object, int *is_temp TSRMLS_DC)
     458             : {
     459           6 :         mysqli_object *obj = (mysqli_object *)zend_objects_get_address(object TSRMLS_CC);
     460           6 :         HashTable *retval, *props = obj->prop_handler;
     461             :         HashPosition pos;
     462             :         mysqli_prop_handler *entry;
     463             : 
     464           6 :         ALLOC_HASHTABLE(retval);
     465           6 :         ZEND_INIT_SYMTABLE_EX(retval, zend_hash_num_elements(props) + 1, 0);
     466             : 
     467           6 :         zend_hash_internal_pointer_reset_ex(props, &pos);
     468         103 :         while (zend_hash_get_current_data_ex(props, (void **)&entry, &pos) == SUCCESS) {
     469             :                 zval member;
     470             :                 zval *value;
     471          91 :                 INIT_ZVAL(member);
     472          91 :                 ZVAL_STRINGL(&member, entry->name, entry->name_len, 0);
     473          91 :                 value = mysqli_read_property(object, &member, BP_VAR_IS, 0 TSRMLS_CC);
     474          91 :                 if (value != EG(uninitialized_zval_ptr)) {
     475          91 :                         Z_ADDREF_P(value);
     476          91 :                         zend_hash_add(retval, entry->name, entry->name_len + 1, &value, sizeof(zval *), NULL);
     477             :                 }
     478          91 :                 zend_hash_move_forward_ex(props, &pos);
     479             :         }
     480             : 
     481           6 :         *is_temp = 1;
     482           6 :         return retval;
     483             : }
     484             : #endif
     485             : 
     486             : /* {{{ mysqli_objects_new
     487             :  */
     488        5738 : PHP_MYSQLI_EXPORT(zend_object_value) mysqli_objects_new(zend_class_entry *class_type TSRMLS_DC)
     489             : {
     490             :         zend_object_value retval;
     491             :         mysqli_object *intern;
     492             :         zend_class_entry *mysqli_base_class;
     493             :         zend_objects_free_object_storage_t free_storage;
     494             : 
     495        5738 :         intern = emalloc(sizeof(mysqli_object));
     496        5738 :         memset(intern, 0, sizeof(mysqli_object));
     497        5738 :         intern->ptr = NULL;
     498        5738 :         intern->prop_handler = NULL;
     499             : 
     500        5738 :         mysqli_base_class = class_type;
     501       11584 :         while (mysqli_base_class->type != ZEND_INTERNAL_CLASS &&
     502          54 :                    mysqli_base_class->parent != NULL) {
     503          54 :                 mysqli_base_class = mysqli_base_class->parent;
     504             :         }
     505        5738 :         zend_hash_find(&classes, mysqli_base_class->name, mysqli_base_class->name_length + 1,
     506        5738 :                                         (void **) &intern->prop_handler);
     507             : 
     508        5738 :         zend_object_std_init(&intern->zo, class_type TSRMLS_CC);
     509        5738 :         object_properties_init(&intern->zo, class_type);
     510             : 
     511             :         /* link object */
     512        5738 :         if (instanceof_function(class_type, mysqli_link_class_entry TSRMLS_CC)) {
     513        1226 :                 free_storage = mysqli_link_free_storage;
     514        4512 :         } else if (instanceof_function(class_type, mysqli_driver_class_entry TSRMLS_CC)) { /* driver object */
     515        1160 :                 free_storage = mysqli_driver_free_storage;
     516        3352 :         } else if (instanceof_function(class_type, mysqli_stmt_class_entry TSRMLS_CC)) { /* stmt object */
     517         947 :                 free_storage = mysqli_stmt_free_storage;
     518        2405 :         } else if (instanceof_function(class_type, mysqli_result_class_entry TSRMLS_CC)) { /* result object */
     519        2399 :                 free_storage = mysqli_result_free_storage;
     520           6 :         } else if (instanceof_function(class_type, mysqli_warning_class_entry TSRMLS_CC)) { /* warning object */
     521           6 :                 free_storage = mysqli_warning_free_storage;
     522             :         } else {
     523           0 :                 free_storage = mysqli_objects_free_storage;
     524             :         }
     525             : 
     526        5738 :         retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, free_storage, NULL TSRMLS_CC);
     527        5738 :         retval.handlers = &mysqli_object_handlers;
     528             : 
     529        5738 :         return retval;
     530             : }
     531             : /* }}} */
     532             : 
     533             : #ifdef MYSQLI_USE_MYSQLND
     534             : #include "ext/mysqlnd/mysqlnd_reverse_api.h"
     535           0 : static MYSQLND *mysqli_convert_zv_to_mysqlnd(zval * zv TSRMLS_DC)
     536             : {
     537           0 :         if (Z_TYPE_P(zv) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zv), mysqli_link_class_entry TSRMLS_CC)) {
     538             :                 MY_MYSQL * mysql;
     539             :                 MYSQLI_RESOURCE  * my_res;
     540           0 :                 mysqli_object * intern = (mysqli_object *)zend_object_store_get_object(zv TSRMLS_CC);
     541           0 :                 if (!(my_res = (MYSQLI_RESOURCE *)intern->ptr)) {
     542             :                         /* We know that we have a mysqli object, so this failure should be emitted */
     543           0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", intern->zo.ce->name);
     544           0 :                         return NULL;
     545             :                 }
     546           0 :                 mysql = (MY_MYSQL *)(my_res->ptr);
     547           0 :                 return mysql ? mysql->mysql : NULL;
     548             :         }
     549           0 :         return NULL;
     550             : }
     551             : 
     552             : static MYSQLND_REVERSE_API mysqli_reverse_api = {
     553             :         &mysqli_module_entry,
     554             :         mysqli_convert_zv_to_mysqlnd
     555             : };
     556             : #endif
     557             : 
     558             : /* {{{ PHP_INI_BEGIN
     559             : */
     560             : PHP_INI_BEGIN()
     561             :         STD_PHP_INI_ENTRY_EX("mysqli.max_links",                      "-1", PHP_INI_SYSTEM,         OnUpdateLong,           max_links,                      zend_mysqli_globals,            mysqli_globals, display_link_numbers)
     562             :         STD_PHP_INI_ENTRY_EX("mysqli.max_persistent",         "-1", PHP_INI_SYSTEM,         OnUpdateLong,           max_persistent,         zend_mysqli_globals,            mysqli_globals, display_link_numbers)
     563             :         STD_PHP_INI_BOOLEAN("mysqli.allow_persistent",                "1",  PHP_INI_SYSTEM,         OnUpdateLong,           allow_persistent,       zend_mysqli_globals,            mysqli_globals)
     564             :         STD_PHP_INI_BOOLEAN("mysqli.rollback_on_cached_plink",        "0",PHP_INI_SYSTEM,           OnUpdateBool,           rollback_on_cached_plink,       zend_mysqli_globals,            mysqli_globals)
     565             :         STD_PHP_INI_ENTRY("mysqli.default_host",                      NULL,   PHP_INI_ALL,            OnUpdateString,         default_host,           zend_mysqli_globals,            mysqli_globals)
     566             :         STD_PHP_INI_ENTRY("mysqli.default_user",                      NULL,   PHP_INI_ALL,            OnUpdateString,         default_user,           zend_mysqli_globals,            mysqli_globals)
     567             :         STD_PHP_INI_ENTRY("mysqli.default_pw",                                NULL,   PHP_INI_ALL,            OnUpdateString,         default_pw,                     zend_mysqli_globals,            mysqli_globals)
     568             :         STD_PHP_INI_ENTRY("mysqli.default_port",                      "3306",       PHP_INI_ALL,            OnUpdateLong,           default_port,           zend_mysqli_globals,            mysqli_globals)
     569             : #ifdef PHP_MYSQL_UNIX_SOCK_ADDR
     570             :         STD_PHP_INI_ENTRY("mysqli.default_socket",                    MYSQL_UNIX_ADDR,PHP_INI_ALL,OnUpdateStringUnempty,      default_socket, zend_mysqli_globals,            mysqli_globals)
     571             : #else
     572             :         STD_PHP_INI_ENTRY("mysqli.default_socket",                    NULL,   PHP_INI_ALL,            OnUpdateStringUnempty,  default_socket, zend_mysqli_globals,            mysqli_globals)
     573             : #endif
     574             :         STD_PHP_INI_BOOLEAN("mysqli.reconnect",                               "0",  PHP_INI_SYSTEM,         OnUpdateLong,           reconnect,                      zend_mysqli_globals,            mysqli_globals)
     575             :         STD_PHP_INI_BOOLEAN("mysqli.allow_local_infile",      "1",  PHP_INI_SYSTEM,         OnUpdateLong,           allow_local_infile,     zend_mysqli_globals,            mysqli_globals)
     576             : PHP_INI_END()
     577             : /* }}} */
     578             : 
     579             : 
     580             : /* {{{ PHP_GINIT_FUNCTION
     581             :  */
     582       21159 : static PHP_GINIT_FUNCTION(mysqli)
     583             : {
     584       21159 :         mysqli_globals->num_links = 0;
     585       21159 :         mysqli_globals->num_active_persistent = 0;
     586       21159 :         mysqli_globals->num_inactive_persistent = 0;
     587       21159 :         mysqli_globals->max_links = -1;
     588       21159 :         mysqli_globals->max_persistent = -1;
     589       21159 :         mysqli_globals->allow_persistent = 1;
     590       21159 :         mysqli_globals->default_port = 0;
     591       21159 :         mysqli_globals->default_host = NULL;
     592       21159 :         mysqli_globals->default_user = NULL;
     593       21159 :         mysqli_globals->default_pw = NULL;
     594       21159 :         mysqli_globals->default_socket = NULL;
     595       21159 :         mysqli_globals->reconnect = 0;
     596       21159 :         mysqli_globals->report_mode = 0;
     597       21159 :         mysqli_globals->report_ht = 0;
     598       21159 :         mysqli_globals->allow_local_infile = 1;
     599             : #ifdef HAVE_EMBEDDED_MYSQLI
     600             :         mysqli_globals->embedded = 1;
     601             : #else
     602       21159 :         mysqli_globals->embedded = 0;
     603             : #endif
     604       21159 :         mysqli_globals->rollback_on_cached_plink = FALSE;
     605       21159 : }
     606             : /* }}} */
     607             : 
     608             : /* {{{ PHP_MINIT_FUNCTION
     609             :  */
     610       21159 : PHP_MINIT_FUNCTION(mysqli)
     611             : {
     612             :         zend_class_entry *ce,cex;
     613       21159 :         zend_object_handlers *std_hnd = zend_get_std_object_handlers();
     614             : 
     615       21159 :         REGISTER_INI_ENTRIES();
     616             : #ifndef MYSQLI_USE_MYSQLND
     617             : #if MYSQL_VERSION_ID >= 40000
     618             :         if (mysql_server_init(0, NULL, NULL)) {
     619             :                 return FAILURE;
     620             :         }
     621             : #endif
     622             : #endif
     623             : 
     624       21159 :         memcpy(&mysqli_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
     625       21159 :         mysqli_object_handlers.clone_obj = NULL;
     626       21159 :         mysqli_object_handlers.read_property = mysqli_read_property;
     627       21159 :         mysqli_object_handlers.write_property = mysqli_write_property;
     628       21159 :         mysqli_object_handlers.get_property_ptr_ptr = std_hnd->get_property_ptr_ptr;
     629       21159 :         mysqli_object_handlers.has_property = mysqli_object_has_property;
     630             : #if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3
     631       21159 :         mysqli_object_handlers.get_debug_info = mysqli_object_get_debug_info;
     632             : #endif
     633             : 
     634       21159 :         zend_hash_init(&classes, 0, NULL, NULL, 1);
     635             : 
     636             :         /* persistent connections */
     637       21159 :         le_pmysqli = zend_register_list_destructors_ex(NULL, php_mysqli_dtor,
     638             :                 "MySqli persistent connection", module_number);
     639             : 
     640       21159 :         INIT_CLASS_ENTRY(cex, "mysqli_sql_exception", mysqli_exception_methods);
     641             : #ifdef HAVE_SPL
     642       21159 :         mysqli_exception_class_entry = zend_register_internal_class_ex(&cex, spl_ce_RuntimeException, NULL TSRMLS_CC);
     643             : #else
     644             :         mysqli_exception_class_entry = zend_register_internal_class_ex(&cex, zend_exception_get_default(TSRMLS_C), NULL TSRMLS_CC);
     645             : #endif
     646       21159 :         mysqli_exception_class_entry->ce_flags |= ZEND_ACC_FINAL;
     647       21159 :         zend_declare_property_long(mysqli_exception_class_entry, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED TSRMLS_CC);
     648       21159 :         zend_declare_property_string(mysqli_exception_class_entry, "sqlstate", sizeof("sqlstate")-1, "00000", ZEND_ACC_PROTECTED TSRMLS_CC);
     649             : 
     650       21159 :         REGISTER_MYSQLI_CLASS_ENTRY("mysqli_driver", mysqli_driver_class_entry, mysqli_driver_methods);
     651       21159 :         ce = mysqli_driver_class_entry;
     652       21159 :         zend_hash_init(&mysqli_driver_properties, 0, NULL, NULL, 1);
     653       21159 :         MYSQLI_ADD_PROPERTIES(&mysqli_driver_properties, mysqli_driver_property_entries);
     654       21159 :         MYSQLI_ADD_PROPERTIES_INFO(ce, mysqli_driver_property_info_entries);
     655       21159 :         zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_driver_properties, sizeof(mysqli_driver_properties), NULL);
     656       21159 :         ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
     657             : 
     658       21159 :         REGISTER_MYSQLI_CLASS_ENTRY("mysqli", mysqli_link_class_entry, mysqli_link_methods);
     659       21159 :         ce = mysqli_link_class_entry;
     660       21159 :         zend_hash_init(&mysqli_link_properties, 0, NULL, NULL, 1);
     661       21159 :         MYSQLI_ADD_PROPERTIES(&mysqli_link_properties, mysqli_link_property_entries);
     662       21159 :         MYSQLI_ADD_PROPERTIES_INFO(ce, mysqli_link_property_info_entries);
     663       21159 :         zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_link_properties, sizeof(mysqli_link_properties), NULL);
     664             : 
     665       21159 :         REGISTER_MYSQLI_CLASS_ENTRY("mysqli_warning", mysqli_warning_class_entry, mysqli_warning_methods);
     666       21159 :         ce = mysqli_warning_class_entry;
     667       21159 :         ce->ce_flags |= ZEND_ACC_FINAL_CLASS | ZEND_ACC_PROTECTED;
     668       21159 :         zend_hash_init(&mysqli_warning_properties, 0, NULL, NULL, 1);
     669       21159 :         MYSQLI_ADD_PROPERTIES(&mysqli_warning_properties, mysqli_warning_property_entries);
     670       21159 :         MYSQLI_ADD_PROPERTIES_INFO(ce, mysqli_warning_property_info_entries);
     671       21159 :         zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_warning_properties, sizeof(mysqli_warning_properties), NULL);
     672             : 
     673       21159 :         REGISTER_MYSQLI_CLASS_ENTRY("mysqli_result", mysqli_result_class_entry, mysqli_result_methods);
     674       21159 :         ce = mysqli_result_class_entry;
     675       21159 :         zend_hash_init(&mysqli_result_properties, 0, NULL, NULL, 1);
     676       21159 :         MYSQLI_ADD_PROPERTIES(&mysqli_result_properties, mysqli_result_property_entries);
     677       21159 :         MYSQLI_ADD_PROPERTIES_INFO(ce, mysqli_result_property_info_entries);
     678       21159 :         mysqli_result_class_entry->get_iterator = php_mysqli_result_get_iterator;
     679       21159 :         mysqli_result_class_entry->iterator_funcs.funcs = &php_mysqli_result_iterator_funcs;
     680       21159 :         zend_class_implements(mysqli_result_class_entry TSRMLS_CC, 1, zend_ce_traversable);
     681       21159 :         zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_result_properties, sizeof(mysqli_result_properties), NULL);
     682             : 
     683       21159 :         REGISTER_MYSQLI_CLASS_ENTRY("mysqli_stmt", mysqli_stmt_class_entry, mysqli_stmt_methods);
     684       21159 :         ce = mysqli_stmt_class_entry;
     685       21159 :         zend_hash_init(&mysqli_stmt_properties, 0, NULL, NULL, 1);
     686       21159 :         MYSQLI_ADD_PROPERTIES(&mysqli_stmt_properties, mysqli_stmt_property_entries);
     687       21159 :         MYSQLI_ADD_PROPERTIES_INFO(ce, mysqli_stmt_property_info_entries);
     688       21159 :         zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_stmt_properties, sizeof(mysqli_stmt_properties), NULL);
     689             : 
     690             :         /* mysqli_options */
     691       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_READ_DEFAULT_GROUP", MYSQL_READ_DEFAULT_GROUP, CONST_CS | CONST_PERSISTENT);
     692       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_READ_DEFAULT_FILE", MYSQL_READ_DEFAULT_FILE, CONST_CS | CONST_PERSISTENT);
     693       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_OPT_CONNECT_TIMEOUT", MYSQL_OPT_CONNECT_TIMEOUT, CONST_CS | CONST_PERSISTENT);
     694       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_OPT_LOCAL_INFILE", MYSQL_OPT_LOCAL_INFILE, CONST_CS | CONST_PERSISTENT);
     695       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_INIT_COMMAND", MYSQL_INIT_COMMAND, CONST_CS | CONST_PERSISTENT);
     696             : #if defined(MYSQLI_USE_MYSQLND)
     697       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_OPT_NET_CMD_BUFFER_SIZE", MYSQLND_OPT_NET_CMD_BUFFER_SIZE, CONST_CS | CONST_PERSISTENT);
     698       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_OPT_NET_READ_BUFFER_SIZE", MYSQLND_OPT_NET_READ_BUFFER_SIZE, CONST_CS | CONST_PERSISTENT);
     699             : #endif
     700             : #ifdef MYSQLND_STRING_TO_INT_CONVERSION
     701       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_OPT_INT_AND_FLOAT_NATIVE", MYSQLND_OPT_INT_AND_FLOAT_NATIVE, CONST_CS | CONST_PERSISTENT);
     702             : #endif
     703             : #if MYSQL_VERSION_ID > 50110 || defined(MYSQLI_USE_MYSQLND)
     704       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_OPT_SSL_VERIFY_SERVER_CERT", MYSQL_OPT_SSL_VERIFY_SERVER_CERT, CONST_CS | CONST_PERSISTENT);
     705             : #endif
     706             : 
     707             : #if MYSQL_VERSION_ID > 50605 || defined(MYSQLI_USE_MYSQLND)
     708       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_SERVER_PUBLIC_KEY", MYSQL_SERVER_PUBLIC_KEY, CONST_CS | CONST_PERSISTENT);
     709             : #endif
     710             : 
     711             :         /* mysqli_real_connect flags */
     712       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_CLIENT_SSL", CLIENT_SSL, CONST_CS | CONST_PERSISTENT);
     713       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_CLIENT_COMPRESS",CLIENT_COMPRESS, CONST_CS | CONST_PERSISTENT);
     714       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_CLIENT_INTERACTIVE", CLIENT_INTERACTIVE, CONST_CS | CONST_PERSISTENT);
     715       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_CLIENT_IGNORE_SPACE", CLIENT_IGNORE_SPACE, CONST_CS | CONST_PERSISTENT);
     716       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_CLIENT_NO_SCHEMA", CLIENT_NO_SCHEMA, CONST_CS | CONST_PERSISTENT);
     717       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_CLIENT_FOUND_ROWS", CLIENT_FOUND_ROWS, CONST_CS | CONST_PERSISTENT);
     718             : 
     719             :         /* for mysqli_query */
     720       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_STORE_RESULT", MYSQLI_STORE_RESULT, CONST_CS | CONST_PERSISTENT);
     721       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_USE_RESULT", MYSQLI_USE_RESULT, CONST_CS | CONST_PERSISTENT);
     722             : #if defined (MYSQLI_USE_MYSQLND)
     723       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_ASYNC", MYSQLI_ASYNC, CONST_CS | CONST_PERSISTENT);
     724       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_STORE_RESULT_COPY_DATA", MYSQLI_STORE_RESULT_COPY_DATA, CONST_CS | CONST_PERSISTENT);
     725             : #endif
     726             : 
     727             :         /* for mysqli_fetch_assoc */
     728       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_ASSOC", MYSQLI_ASSOC, CONST_CS | CONST_PERSISTENT);
     729       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_NUM", MYSQLI_NUM, CONST_CS | CONST_PERSISTENT);
     730       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_BOTH", MYSQLI_BOTH, CONST_CS | CONST_PERSISTENT);
     731             : 
     732             :         /* for mysqli_stmt_set_attr */
     733       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH", STMT_ATTR_UPDATE_MAX_LENGTH, CONST_CS | CONST_PERSISTENT);
     734             : 
     735             : #if MYSQL_VERSION_ID > 50003 || defined(MYSQLI_USE_MYSQLND)
     736       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_STMT_ATTR_CURSOR_TYPE", STMT_ATTR_CURSOR_TYPE, CONST_CS | CONST_PERSISTENT);
     737       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_CURSOR_TYPE_NO_CURSOR", CURSOR_TYPE_NO_CURSOR, CONST_CS | CONST_PERSISTENT);
     738       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_CURSOR_TYPE_READ_ONLY", CURSOR_TYPE_READ_ONLY, CONST_CS | CONST_PERSISTENT);
     739       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_CURSOR_TYPE_FOR_UPDATE", CURSOR_TYPE_FOR_UPDATE, CONST_CS | CONST_PERSISTENT);
     740       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_CURSOR_TYPE_SCROLLABLE", CURSOR_TYPE_SCROLLABLE, CONST_CS | CONST_PERSISTENT);
     741             : #endif
     742             : 
     743             : #if MYSQL_VERSION_ID > 50007 || defined(MYSQLI_USE_MYSQLND)
     744       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_STMT_ATTR_PREFETCH_ROWS", STMT_ATTR_PREFETCH_ROWS, CONST_CS | CONST_PERSISTENT);
     745             : #endif
     746             : 
     747             :         /* column information */
     748       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_NOT_NULL_FLAG", NOT_NULL_FLAG, CONST_CS | CONST_PERSISTENT);
     749       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_PRI_KEY_FLAG", PRI_KEY_FLAG, CONST_CS | CONST_PERSISTENT);
     750       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_UNIQUE_KEY_FLAG", UNIQUE_KEY_FLAG, CONST_CS | CONST_PERSISTENT);
     751       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_MULTIPLE_KEY_FLAG", MULTIPLE_KEY_FLAG, CONST_CS | CONST_PERSISTENT);
     752       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_BLOB_FLAG", BLOB_FLAG, CONST_CS | CONST_PERSISTENT);
     753       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_UNSIGNED_FLAG", UNSIGNED_FLAG, CONST_CS | CONST_PERSISTENT);
     754       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_ZEROFILL_FLAG", ZEROFILL_FLAG, CONST_CS | CONST_PERSISTENT);
     755       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_AUTO_INCREMENT_FLAG", AUTO_INCREMENT_FLAG, CONST_CS | CONST_PERSISTENT);
     756       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TIMESTAMP_FLAG", TIMESTAMP_FLAG, CONST_CS | CONST_PERSISTENT);
     757       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_SET_FLAG", SET_FLAG, CONST_CS | CONST_PERSISTENT);
     758       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_NUM_FLAG", NUM_FLAG, CONST_CS | CONST_PERSISTENT);
     759       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_PART_KEY_FLAG", PART_KEY_FLAG, CONST_CS | CONST_PERSISTENT);
     760       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_GROUP_FLAG", GROUP_FLAG, CONST_CS | CONST_PERSISTENT);
     761       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_ENUM_FLAG", ENUM_FLAG, CONST_CS | CONST_PERSISTENT);
     762       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_BINARY_FLAG", BINARY_FLAG, CONST_CS | CONST_PERSISTENT);
     763             : #if MYSQL_VERSION_ID > 50001 || defined(MYSQLI_USE_MYSQLND)
     764       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_NO_DEFAULT_VALUE_FLAG", NO_DEFAULT_VALUE_FLAG, CONST_CS | CONST_PERSISTENT);
     765             : #endif
     766             : 
     767             : #if (MYSQL_VERSION_ID > 51122 && MYSQL_VERSION_ID < 60000) || (MYSQL_VERSION_ID > 60003) || defined(MYSQLI_USE_MYSQLND)
     768       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_ON_UPDATE_NOW_FLAG", ON_UPDATE_NOW_FLAG, CONST_CS | CONST_PERSISTENT);
     769             : #endif
     770             : 
     771       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_DECIMAL", FIELD_TYPE_DECIMAL, CONST_CS | CONST_PERSISTENT);
     772       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_TINY", FIELD_TYPE_TINY, CONST_CS | CONST_PERSISTENT);
     773       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_SHORT", FIELD_TYPE_SHORT, CONST_CS | CONST_PERSISTENT);
     774       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_LONG", FIELD_TYPE_LONG, CONST_CS | CONST_PERSISTENT);
     775       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_FLOAT", FIELD_TYPE_FLOAT, CONST_CS | CONST_PERSISTENT);
     776       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_DOUBLE", FIELD_TYPE_DOUBLE, CONST_CS | CONST_PERSISTENT);
     777       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_NULL", FIELD_TYPE_NULL, CONST_CS | CONST_PERSISTENT);
     778       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_TIMESTAMP", FIELD_TYPE_TIMESTAMP, CONST_CS | CONST_PERSISTENT);
     779       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_LONGLONG", FIELD_TYPE_LONGLONG, CONST_CS | CONST_PERSISTENT);
     780       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_INT24", FIELD_TYPE_INT24, CONST_CS | CONST_PERSISTENT);
     781       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_DATE", FIELD_TYPE_DATE, CONST_CS | CONST_PERSISTENT);
     782       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_TIME", FIELD_TYPE_TIME, CONST_CS | CONST_PERSISTENT);
     783       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_DATETIME", FIELD_TYPE_DATETIME    , CONST_CS | CONST_PERSISTENT);
     784       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_YEAR", FIELD_TYPE_YEAR, CONST_CS | CONST_PERSISTENT);
     785       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_NEWDATE", FIELD_TYPE_NEWDATE, CONST_CS | CONST_PERSISTENT);
     786       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_ENUM", FIELD_TYPE_ENUM, CONST_CS | CONST_PERSISTENT);
     787       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_SET", FIELD_TYPE_SET, CONST_CS | CONST_PERSISTENT);
     788       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_TINY_BLOB", FIELD_TYPE_TINY_BLOB, CONST_CS | CONST_PERSISTENT);
     789       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_MEDIUM_BLOB", FIELD_TYPE_MEDIUM_BLOB, CONST_CS | CONST_PERSISTENT);
     790       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_LONG_BLOB", FIELD_TYPE_LONG_BLOB, CONST_CS | CONST_PERSISTENT);
     791       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_BLOB", FIELD_TYPE_BLOB, CONST_CS | CONST_PERSISTENT);
     792       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_VAR_STRING", FIELD_TYPE_VAR_STRING, CONST_CS | CONST_PERSISTENT);
     793       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_STRING", FIELD_TYPE_STRING, CONST_CS | CONST_PERSISTENT);
     794       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_CHAR", FIELD_TYPE_CHAR, CONST_CS | CONST_PERSISTENT);
     795       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_INTERVAL", FIELD_TYPE_INTERVAL, CONST_CS | CONST_PERSISTENT);
     796       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_GEOMETRY", FIELD_TYPE_GEOMETRY, CONST_CS | CONST_PERSISTENT);
     797             : 
     798             : #if MYSQL_VERSION_ID > 50002 || defined(MYSQLI_USE_MYSQLND)
     799       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_NEWDECIMAL", FIELD_TYPE_NEWDECIMAL, CONST_CS | CONST_PERSISTENT);
     800       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_BIT", FIELD_TYPE_BIT, CONST_CS | CONST_PERSISTENT);
     801             : #endif
     802             : 
     803       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_SET_CHARSET_NAME", MYSQL_SET_CHARSET_NAME, CONST_CS | CONST_PERSISTENT);
     804       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_SET_CHARSET_DIR", MYSQL_SET_CHARSET_DIR, CONST_CS | CONST_PERSISTENT);
     805             : 
     806             :         /* bind support */
     807       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_NO_DATA", MYSQL_NO_DATA, CONST_CS | CONST_PERSISTENT);
     808             : #ifdef MYSQL_DATA_TRUNCATED
     809       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_DATA_TRUNCATED", MYSQL_DATA_TRUNCATED, CONST_CS | CONST_PERSISTENT);
     810             : #endif
     811             : 
     812             :         /* reporting */
     813       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_REPORT_INDEX", MYSQLI_REPORT_INDEX, CONST_CS | CONST_PERSISTENT);
     814       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_REPORT_ERROR", MYSQLI_REPORT_ERROR, CONST_CS | CONST_PERSISTENT);
     815       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_REPORT_STRICT", MYSQLI_REPORT_STRICT, CONST_CS | CONST_PERSISTENT);
     816       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_REPORT_ALL", MYSQLI_REPORT_ALL, CONST_CS | CONST_PERSISTENT);
     817       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_REPORT_OFF", 0, CONST_CS | CONST_PERSISTENT);
     818             : 
     819             :         /* We use non-nested macros with expansion, as VC has problems */
     820             : #ifdef MYSQLI_USE_MYSQLND
     821       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_DEBUG_TRACE_ENABLED", MYSQLND_DBG_ENABLED, CONST_CS | CONST_PERSISTENT);
     822             : #else
     823             : #ifdef DBUG_ON
     824             :         REGISTER_LONG_CONSTANT("MYSQLI_DEBUG_TRACE_ENABLED", 1, CONST_CS | CONST_PERSISTENT);
     825             : #else
     826             :         REGISTER_LONG_CONSTANT("MYSQLI_DEBUG_TRACE_ENABLED", 0, CONST_CS | CONST_PERSISTENT);
     827             : #endif
     828             : #endif
     829             : 
     830       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_SERVER_QUERY_NO_GOOD_INDEX_USED", SERVER_QUERY_NO_GOOD_INDEX_USED, CONST_CS | CONST_PERSISTENT);
     831       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_SERVER_QUERY_NO_INDEX_USED", SERVER_QUERY_NO_INDEX_USED, CONST_CS | CONST_PERSISTENT);
     832             : #ifdef SERVER_QUERY_WAS_SLOW
     833       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_SERVER_QUERY_WAS_SLOW", SERVER_QUERY_WAS_SLOW, CONST_CS | CONST_PERSISTENT);
     834             : #endif
     835             : #ifdef SERVER_PS_OUT_PARAMS
     836       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_SERVER_PS_OUT_PARAMS", SERVER_PS_OUT_PARAMS, CONST_CS | CONST_PERSISTENT);
     837             : #endif
     838             : 
     839       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_REFRESH_GRANT",      REFRESH_GRANT, CONST_CS | CONST_PERSISTENT);
     840       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_REFRESH_LOG",        REFRESH_LOG, CONST_CS | CONST_PERSISTENT);
     841       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_REFRESH_TABLES",     REFRESH_TABLES, CONST_CS | CONST_PERSISTENT);
     842       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_REFRESH_HOSTS",      REFRESH_HOSTS, CONST_CS | CONST_PERSISTENT);
     843       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_REFRESH_STATUS",     REFRESH_STATUS, CONST_CS | CONST_PERSISTENT);
     844       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_REFRESH_THREADS",    REFRESH_THREADS, CONST_CS | CONST_PERSISTENT);
     845       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_REFRESH_SLAVE",      REFRESH_SLAVE, CONST_CS | CONST_PERSISTENT);
     846       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_REFRESH_MASTER",     REFRESH_MASTER, CONST_CS | CONST_PERSISTENT);
     847             : #ifdef REFRESH_BACKUP_LOG
     848       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_REFRESH_BACKUP_LOG", REFRESH_BACKUP_LOG, CONST_CS | CONST_PERSISTENT);
     849             : #endif
     850             : 
     851             : #if (MYSQL_VERSION_ID >= 50611 && defined(CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS)) || defined(MYSQLI_USE_MYSQLND)
     852       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_OPT_CAN_HANDLE_EXPIRED_PASSWORDS", MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, CONST_CS | CONST_PERSISTENT);
     853             : #endif
     854             : 
     855       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TRANS_START_WITH_CONSISTENT_SNAPSHOT", TRANS_START_WITH_CONSISTENT_SNAPSHOT, CONST_CS | CONST_PERSISTENT);
     856       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TRANS_START_READ_WRITE", TRANS_START_READ_WRITE, CONST_CS | CONST_PERSISTENT);
     857       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TRANS_START_READ_ONLY", TRANS_START_READ_ONLY, CONST_CS | CONST_PERSISTENT);
     858             : 
     859       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TRANS_COR_AND_CHAIN", TRANS_COR_AND_CHAIN, CONST_CS | CONST_PERSISTENT);
     860       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TRANS_COR_AND_NO_CHAIN", TRANS_COR_AND_NO_CHAIN, CONST_CS | CONST_PERSISTENT);
     861       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TRANS_COR_RELEASE", TRANS_COR_RELEASE, CONST_CS | CONST_PERSISTENT);
     862       21159 :         REGISTER_LONG_CONSTANT("MYSQLI_TRANS_COR_NO_RELEASE", TRANS_COR_NO_RELEASE, CONST_CS | CONST_PERSISTENT);
     863             : 
     864             : 
     865             : #ifdef MYSQLI_USE_MYSQLND
     866       21159 :         mysqlnd_reverse_api_register_api(&mysqli_reverse_api TSRMLS_CC);
     867             : #endif
     868             : 
     869       21159 :         return SUCCESS;
     870             : }
     871             : /* }}} */
     872             : 
     873             : /* {{{ PHP_MSHUTDOWN_FUNCTION
     874             :  */
     875       21192 : PHP_MSHUTDOWN_FUNCTION(mysqli)
     876             : {
     877             : #ifndef MYSQLI_USE_MYSQLND
     878             : #if MYSQL_VERSION_ID >= 40000
     879             : #ifdef PHP_WIN32
     880             :         unsigned long client_ver = mysql_get_client_version();
     881             :         /*
     882             :           Can't call mysql_server_end() multiple times prior to 5.0.46 on Windows.
     883             :           PHP bug#41350 MySQL bug#25621
     884             :         */
     885             :         if ((client_ver >= 50046 && client_ver < 50100) || client_ver > 50122) {
     886             :                 mysql_server_end();
     887             :         }
     888             : #else
     889             :         mysql_server_end();
     890             : #endif
     891             : #endif
     892             : #endif
     893             : 
     894       21192 :         zend_hash_destroy(&mysqli_driver_properties);
     895       21192 :         zend_hash_destroy(&mysqli_result_properties);
     896       21192 :         zend_hash_destroy(&mysqli_stmt_properties);
     897       21192 :         zend_hash_destroy(&mysqli_warning_properties);
     898       21192 :         zend_hash_destroy(&mysqli_link_properties);
     899       21192 :         zend_hash_destroy(&classes);
     900             : 
     901       21192 :         UNREGISTER_INI_ENTRIES();
     902       21192 :         return SUCCESS;
     903             : }
     904             : /* }}} */
     905             : 
     906             : /* {{{ PHP_RINIT_FUNCTION
     907             :  */
     908       21116 : PHP_RINIT_FUNCTION(mysqli)
     909             : {
     910             : #if !defined(MYSQLI_USE_MYSQLND) && defined(ZTS) && MYSQL_VERSION_ID >= 40000
     911             :         if (mysql_thread_init()) {
     912             :                 return FAILURE;
     913             :         }
     914             : #endif
     915       21116 :         MyG(error_msg) = NULL;
     916       21116 :         MyG(error_no) = 0;
     917       21116 :         MyG(report_mode) = 0;
     918             : 
     919       21116 :         return SUCCESS;
     920             : }
     921             : /* }}} */
     922             : 
     923             : #if defined(A0) && defined(MYSQLI_USE_MYSQLND)
     924             : static void php_mysqli_persistent_helper_for_every(void *p)
     925             : {
     926             :         TSRMLS_FETCH();
     927             :         mysqlnd_end_psession((MYSQLND *) p);
     928             : } /* }}} */
     929             : 
     930             : 
     931             : static int php_mysqli_persistent_helper_once(zend_rsrc_list_entry *le TSRMLS_DC)
     932             : {
     933             :         if (le->type == php_le_pmysqli()) {
     934             :                 mysqli_plist_entry *plist = (mysqli_plist_entry *) le->ptr;
     935             :                 zend_ptr_stack_apply(&plist->free_links, php_mysqli_persistent_helper_for_every);
     936             :         }
     937             :         return ZEND_HASH_APPLY_KEEP;
     938             : } /* }}} */
     939             : #endif
     940             : 
     941             : 
     942             : /* {{{ PHP_RSHUTDOWN_FUNCTION
     943             :  */
     944       21151 : PHP_RSHUTDOWN_FUNCTION(mysqli)
     945             : {
     946             :         /* check persistent connections, move used to free */
     947             : 
     948             : #if !defined(MYSQLI_USE_MYSQLND) && defined(ZTS) && MYSQL_VERSION_ID >= 40000
     949             :         mysql_thread_end();
     950             : #endif
     951       21151 :         if (MyG(error_msg)) {
     952           8 :                 efree(MyG(error_msg));
     953             :         }
     954             : #if defined(A0) && defined(MYSQLI_USE_MYSQLND)
     955             :         /* psession is being called when the connection is freed - explicitly or implicitly */
     956             :         zend_hash_apply(&EG(persistent_list), (apply_func_t) php_mysqli_persistent_helper_once TSRMLS_CC);
     957             : #endif
     958       21151 :         return SUCCESS;
     959             : }
     960             : /* }}} */
     961             : 
     962             : 
     963             : /* {{{ PHP_MINFO_FUNCTION
     964             :  */
     965         150 : PHP_MINFO_FUNCTION(mysqli)
     966             : {
     967             :         char buf[32];
     968             : 
     969         150 :         php_info_print_table_start();
     970         150 :         php_info_print_table_header(2, "MysqlI Support", "enabled");
     971         150 :         php_info_print_table_row(2, "Client API library version", mysql_get_client_info());
     972         150 :         snprintf(buf, sizeof(buf), "%ld", MyG(num_active_persistent));
     973         150 :         php_info_print_table_row(2, "Active Persistent Links", buf);
     974         150 :         snprintf(buf, sizeof(buf), "%ld", MyG(num_inactive_persistent));
     975         150 :         php_info_print_table_row(2, "Inactive Persistent Links", buf);
     976         150 :         snprintf(buf, sizeof(buf), "%ld", MyG(num_links));
     977         150 :         php_info_print_table_row(2, "Active Links", buf);
     978             : #if !defined(MYSQLI_USE_MYSQLND)
     979             :         php_info_print_table_row(2, "Client API header version", MYSQL_SERVER_VERSION);
     980             :         php_info_print_table_row(2, "MYSQLI_SOCKET", MYSQL_UNIX_ADDR);
     981             : #endif
     982         150 :         php_info_print_table_end();
     983             : 
     984         150 :         DISPLAY_INI_ENTRIES();
     985         150 : }
     986             : /* }}} */
     987             : 
     988             : 
     989             : /* Dependancies */
     990             : static const  zend_module_dep mysqli_deps[] = {
     991             : #if defined(HAVE_SPL) && ((PHP_MAJOR_VERSION > 5) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1))
     992             :         ZEND_MOD_REQUIRED("spl")
     993             : #endif
     994             : #if defined(MYSQLI_USE_MYSQLND)
     995             :         ZEND_MOD_REQUIRED("mysqlnd")
     996             : #endif
     997             :         ZEND_MOD_END
     998             : };
     999             : 
    1000             : /* {{{ mysqli_module_entry
    1001             :  */
    1002             : zend_module_entry mysqli_module_entry = {
    1003             : #if ZEND_MODULE_API_NO >= 20050922
    1004             :         STANDARD_MODULE_HEADER_EX, NULL,
    1005             :         mysqli_deps,
    1006             : #elif ZEND_MODULE_API_NO >= 20010901
    1007             :         STANDARD_MODULE_HEADER,
    1008             : #endif
    1009             :         "mysqli",
    1010             :         mysqli_functions,
    1011             :         PHP_MINIT(mysqli),
    1012             :         PHP_MSHUTDOWN(mysqli),
    1013             :         PHP_RINIT(mysqli),
    1014             :         PHP_RSHUTDOWN(mysqli),
    1015             :         PHP_MINFO(mysqli),
    1016             :         "0.1", /* Replace with version number for your extension */
    1017             :         PHP_MODULE_GLOBALS(mysqli),
    1018             :         PHP_GINIT(mysqli),
    1019             :         NULL,
    1020             :         NULL,
    1021             :         STANDARD_MODULE_PROPERTIES_EX
    1022             : };
    1023             : /* }}} */
    1024             : 
    1025             : #ifdef COMPILE_DL_MYSQLI
    1026             : ZEND_GET_MODULE(mysqli)
    1027             : #endif
    1028             : 
    1029             : 
    1030             : /* {{{ mixed mysqli_stmt_construct()
    1031             : constructor for statement object.
    1032             : Parameters:
    1033             :   object -> mysqli_stmt_init
    1034             :   object, query -> mysqli_prepare
    1035             : */
    1036           8 : PHP_FUNCTION(mysqli_stmt_construct)
    1037             : {
    1038             :         MY_MYSQL                        *mysql;
    1039             :         zval                            *mysql_link;
    1040             :         MY_STMT                         *stmt;
    1041             :         MYSQLI_RESOURCE         *mysqli_resource;
    1042             :         char                            *statement;
    1043             :         int                                     statement_len;
    1044             : 
    1045           8 :         switch (ZEND_NUM_ARGS())
    1046             :         {
    1047             :                 case 1:  /* mysql_stmt_init */
    1048           2 :                         if (zend_parse_parameters(1 TSRMLS_CC, "O", &mysql_link, mysqli_link_class_entry)==FAILURE) {
    1049           1 :                                 return;
    1050             :                         }
    1051           1 :                         MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
    1052             : 
    1053           1 :                         stmt = (MY_STMT *)ecalloc(1,sizeof(MY_STMT));
    1054             : 
    1055           1 :                         stmt->stmt = mysql_stmt_init(mysql->mysql);
    1056           1 :                 break;
    1057             :                 case 2:
    1058           5 :                         if (zend_parse_parameters(2 TSRMLS_CC, "Os", &mysql_link, mysqli_link_class_entry, &statement, &statement_len)==FAILURE) {
    1059           1 :                                 return;
    1060             :                         }
    1061           4 :                         MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
    1062             : 
    1063           4 :                         stmt = (MY_STMT *)ecalloc(1,sizeof(MY_STMT));
    1064             : 
    1065           4 :                         if ((stmt->stmt = mysql_stmt_init(mysql->mysql))) {
    1066           4 :                                 mysql_stmt_prepare(stmt->stmt, (char *)statement, statement_len);
    1067             :                         }
    1068           4 :                 break;
    1069             :                 default:
    1070           1 :                         WRONG_PARAM_COUNT;
    1071             :                 break;
    1072             :         }
    1073             : 
    1074           5 :         if (!stmt->stmt) {
    1075           0 :                 efree(stmt);
    1076           0 :                 RETURN_FALSE;
    1077             :         }
    1078             : #ifndef MYSQLI_USE_MYSQLND
    1079             :         stmt->link_handle = Z_OBJ_HANDLE(*mysql_link);
    1080             :         zend_objects_store_add_ref_by_handle(stmt->link_handle TSRMLS_CC);
    1081             : #endif
    1082             : 
    1083           5 :         mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
    1084           5 :         mysqli_resource->ptr = (void *)stmt;
    1085           5 :         mysqli_resource->status = (ZEND_NUM_ARGS() == 1) ? MYSQLI_STATUS_INITIALIZED : MYSQLI_STATUS_VALID;
    1086             : 
    1087           5 :         ((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->ptr = mysqli_resource;
    1088             : }
    1089             : /* }}} */
    1090             : 
    1091             : /* {{{ mixed mysqli_result_construct()
    1092             : constructor for result object.
    1093             : Parameters:
    1094             :   object [, mode] -> mysqli_store/use_result
    1095             : */
    1096          15 : PHP_FUNCTION(mysqli_result_construct)
    1097             : {
    1098             :         MY_MYSQL                        *mysql;
    1099          15 :         MYSQL_RES                       *result = NULL;
    1100             :         zval                            *mysql_link;
    1101             :         MYSQLI_RESOURCE         *mysqli_resource;
    1102          15 :         long                            resmode = MYSQLI_STORE_RESULT;
    1103             : 
    1104          15 :         switch (ZEND_NUM_ARGS()) {
    1105             :                 case 1:
    1106           9 :                         if (zend_parse_parameters(1 TSRMLS_CC, "O", &mysql_link, mysqli_link_class_entry)==FAILURE) {
    1107           1 :                                 return;
    1108             :                         }
    1109           8 :                         break;
    1110             :                 case 2:
    1111           5 :                         if (zend_parse_parameters(2 TSRMLS_CC, "Ol", &mysql_link, mysqli_link_class_entry, &resmode)==FAILURE) {
    1112           1 :                                 return;
    1113             :                         }
    1114           4 :                         break;
    1115             :                 default:
    1116           1 :                         WRONG_PARAM_COUNT;
    1117             :         }
    1118             : 
    1119          12 :         MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
    1120             : 
    1121           8 :         switch (resmode) {
    1122             :                 case MYSQLI_STORE_RESULT:
    1123           6 :                         result = mysql_store_result(mysql->mysql);
    1124           6 :                         break;
    1125             :                 case MYSQLI_USE_RESULT:
    1126           1 :                         result = mysql_use_result(mysql->mysql);
    1127           1 :                         break;
    1128             :                 default:
    1129           1 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid value for resultmode");
    1130             :         }
    1131             : 
    1132           8 :         if (!result) {
    1133           6 :                 RETURN_FALSE;
    1134             :         }
    1135             : 
    1136           2 :         mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
    1137           2 :         mysqli_resource->ptr = (void *)result;
    1138           2 :         mysqli_resource->status = MYSQLI_STATUS_VALID;
    1139             : 
    1140           2 :         ((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->ptr = mysqli_resource;
    1141             : 
    1142             : }
    1143             : /* }}} */
    1144             : 
    1145             : 
    1146             : /* {{{ php_mysqli_fetch_into_hash_aux
    1147             :  */
    1148       59922 : void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * result, long fetchtype TSRMLS_DC)
    1149             : {
    1150             : #if !defined(MYSQLI_USE_MYSQLND)
    1151             :         MYSQL_ROW row;
    1152             :         unsigned int    i;
    1153             :         MYSQL_FIELD             *fields;
    1154             :         unsigned long   *field_len;
    1155             :         
    1156             :         if (!(row = mysql_fetch_row(result))) {
    1157             :                 RETURN_NULL();
    1158             :         }
    1159             : 
    1160             :         if (fetchtype & MYSQLI_ASSOC) {
    1161             :                 fields = mysql_fetch_fields(result);
    1162             :         }
    1163             : 
    1164             :         array_init(return_value);
    1165             :         field_len = mysql_fetch_lengths(result);
    1166             : 
    1167             :         for (i = 0; i < mysql_num_fields(result); i++) {
    1168             :                 if (row[i]) {
    1169             :                         zval *res;
    1170             : 
    1171             :                         MAKE_STD_ZVAL(res);
    1172             : 
    1173             : #if MYSQL_VERSION_ID > 50002
    1174             :                         if (mysql_fetch_field_direct(result, i)->type == MYSQL_TYPE_BIT) {
    1175             :                                 my_ulonglong llval;
    1176             :                                 char tmp[22];
    1177             :                                 switch (field_len[i]) {
    1178             :                                         case 8:llval = (my_ulonglong)  bit_uint8korr(row[i]);break;
    1179             :                                         case 7:llval = (my_ulonglong)  bit_uint7korr(row[i]);break;
    1180             :                                         case 6:llval = (my_ulonglong)  bit_uint6korr(row[i]);break;
    1181             :                                         case 5:llval = (my_ulonglong)  bit_uint5korr(row[i]);break;
    1182             :                                         case 4:llval = (my_ulonglong)  bit_uint4korr(row[i]);break;
    1183             :                                         case 3:llval = (my_ulonglong)  bit_uint3korr(row[i]);break;
    1184             :                                         case 2:llval = (my_ulonglong)  bit_uint2korr(row[i]);break;
    1185             :                                         case 1:llval = (my_ulonglong)  uint1korr(row[i]);break;
    1186             :                                 }
    1187             :                                 /* even though lval is declared as unsigned, the value
    1188             :                                  * may be negative. Therefor we cannot use MYSQLI_LLU_SPEC and must
    1189             :                                  * use MYSQLI_LL_SPEC.
    1190             :                                  */
    1191             :                                 snprintf(tmp, sizeof(tmp), (mysql_fetch_field_direct(result, i)->flags & UNSIGNED_FLAG)? MYSQLI_LLU_SPEC : MYSQLI_LL_SPEC, llval);
    1192             :                                 ZVAL_STRING(res, tmp, 1);
    1193             :                         } else
    1194             : #endif
    1195             :                         {
    1196             : 
    1197             : #if PHP_API_VERSION < 20100412
    1198             :                                 /* check if we need magic quotes */
    1199             :                                 if (PG(magic_quotes_runtime)) {
    1200             :                                         Z_TYPE_P(res) = IS_STRING;
    1201             :                                         Z_STRVAL_P(res) = php_addslashes(row[i], field_len[i], &Z_STRLEN_P(res), 0 TSRMLS_CC);
    1202             :                                 } else {
    1203             : #endif
    1204             :                                         ZVAL_STRINGL(res, row[i], field_len[i], 1);
    1205             : #if PHP_API_VERSION < 20100412
    1206             :                                 }
    1207             : #endif
    1208             :                         }
    1209             : 
    1210             :                         if (fetchtype & MYSQLI_NUM) {
    1211             :                                 add_index_zval(return_value, i, res);
    1212             :                         }
    1213             :                         if (fetchtype & MYSQLI_ASSOC) {
    1214             :                                 if (fetchtype & MYSQLI_NUM) {
    1215             :                                         Z_ADDREF_P(res);
    1216             :                                 }
    1217             :                                 add_assoc_zval(return_value, fields[i].name, res);
    1218             :                         }
    1219             :                 } else {
    1220             :                         if (fetchtype & MYSQLI_NUM) {
    1221             :                                 add_index_null(return_value, i);
    1222             :                         }
    1223             :                         if (fetchtype & MYSQLI_ASSOC) {
    1224             :                                 add_assoc_null(return_value, fields[i].name);
    1225             :                         }
    1226             :                 }
    1227             :         }
    1228             : #else
    1229       59922 :         mysqlnd_fetch_into(result, ((fetchtype & MYSQLI_NUM)? MYSQLND_FETCH_NUM:0) | ((fetchtype & MYSQLI_ASSOC)? MYSQLND_FETCH_ASSOC:0), return_value, MYSQLND_MYSQLI);
    1230             : #endif
    1231       59922 : }
    1232             : /* }}} */
    1233             : 
    1234             : 
    1235             : /* {{{ php_mysqli_fetch_into_hash
    1236             :  */
    1237       59919 : void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags, int into_object)
    1238             : {
    1239             :         MYSQL_RES               *result;
    1240             :         zval                    *mysql_result;
    1241             :         long                    fetchtype;
    1242       59919 :         zval                    *ctor_params = NULL;
    1243       59919 :         zend_class_entry *ce = NULL;
    1244             : 
    1245       59919 :         if (into_object) {
    1246             :                 char *class_name;
    1247             :                 int class_name_len;
    1248             : 
    1249          33 :                 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|sz", &mysql_result, mysqli_result_class_entry, &class_name, &class_name_len, &ctor_params) == FAILURE) {
    1250           5 :                         return;
    1251             :                 }
    1252          28 :                 if (ZEND_NUM_ARGS() < (getThis() ? 1 : 2)) {
    1253          12 :                         ce = zend_standard_class_def;
    1254             :                 } else {
    1255          16 :                         ce = zend_fetch_class(class_name, class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
    1256             :                 }
    1257          26 :                 if (!ce) {
    1258           0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not find class '%s'", class_name);
    1259           0 :                         return;
    1260             :                 }
    1261          26 :                 fetchtype = MYSQLI_ASSOC;
    1262             :         } else {
    1263       59886 :                 if (override_flags) {
    1264       18336 :                         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
    1265           6 :                                 return;
    1266             :                         }
    1267       18330 :                         fetchtype = override_flags;
    1268             :                 } else {
    1269       41550 :                         fetchtype = MYSQLI_BOTH;
    1270       41550 :                         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|l", &mysql_result, mysqli_result_class_entry, &fetchtype) == FAILURE) {
    1271           2 :                                 return;
    1272             :                         }
    1273             :                 }
    1274             :         }
    1275       59904 :         MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
    1276             : 
    1277       59891 :         if (fetchtype < MYSQLI_ASSOC || fetchtype > MYSQLI_BOTH) {
    1278           4 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "The result type should be either MYSQLI_NUM, MYSQLI_ASSOC or MYSQLI_BOTH");
    1279           4 :                 RETURN_FALSE;
    1280             :         }
    1281             : 
    1282       59887 :         php_mysqli_fetch_into_hash_aux(return_value, result, fetchtype TSRMLS_CC);
    1283             : 
    1284       59887 :         if (into_object && Z_TYPE_P(return_value) == IS_ARRAY) {
    1285          18 :                 zval dataset = *return_value;
    1286             :                 zend_fcall_info fci;
    1287             :                 zend_fcall_info_cache fcc;
    1288             :                 zval *retval_ptr;
    1289             : 
    1290          18 :                 object_and_properties_init(return_value, ce, NULL);
    1291          18 :                 zend_merge_properties(return_value, Z_ARRVAL(dataset), 1 TSRMLS_CC);
    1292             : 
    1293          18 :                 if (ce->constructor) {
    1294           9 :                         fci.size = sizeof(fci);
    1295           9 :                         fci.function_table = &ce->function_table;
    1296           9 :                         fci.function_name = NULL;
    1297           9 :                         fci.symbol_table = NULL;
    1298           9 :                         fci.object_ptr = return_value;
    1299           9 :                         fci.retval_ptr_ptr = &retval_ptr;
    1300           9 :                         fci.params = NULL;
    1301           9 :                         fci.param_count = 0;
    1302           9 :                         fci.no_separation = 1;
    1303             : 
    1304           9 :                         if (ctor_params && Z_TYPE_P(ctor_params) != IS_NULL) {
    1305           8 :                                 if (zend_fcall_info_args(&fci, ctor_params TSRMLS_CC) == FAILURE) {
    1306             :                                         /* Two problems why we throw exceptions here: PHP is typeless
    1307             :                                          * and hence passing one argument that's not an array could be
    1308             :                                          * by mistake and the other way round is possible, too. The
    1309             :                                          * single value is an array. Also we'd have to make that one
    1310             :                                          * argument passed by reference.
    1311             :                                          */
    1312           1 :                                         zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Parameter ctor_params must be an array", 0 TSRMLS_CC);
    1313           1 :                                         return;
    1314             :                                 }
    1315             :                         }
    1316             : 
    1317           8 :                         fcc.initialized = 1;
    1318           8 :                         fcc.function_handler = ce->constructor;
    1319           8 :                         fcc.calling_scope = EG(scope);
    1320           8 :                         fcc.called_scope = Z_OBJCE_P(return_value);
    1321           8 :                         fcc.object_ptr = return_value;
    1322             : 
    1323           8 :                         if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) {
    1324           0 :                                 zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Could not execute %s::%s()", ce->name, ce->constructor->common.function_name);
    1325             :                         } else {
    1326           8 :                                 if (retval_ptr) {
    1327           8 :                                         zval_ptr_dtor(&retval_ptr);
    1328             :                                 }
    1329             :                         }
    1330           8 :                         if (fci.params) {
    1331           7 :                                 efree(fci.params);
    1332             :                         }
    1333           9 :                 } else if (ctor_params) {
    1334           1 :                         zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Class %s does not have a constructor hence you cannot use ctor_params", ce->name);
    1335             :                 }
    1336             :         }
    1337             : }
    1338             : /* }}} */
    1339             : 
    1340             : /*
    1341             :  * Local variables:
    1342             :  * tab-width: 4
    1343             :  * c-basic-offset: 4
    1344             :  * End:
    1345             :  * vim600: noet sw=4 ts=4 fdm=marker
    1346             :  * vim<600: noet sw=4 ts=4
    1347             :  */

Generated by: LCOV version 1.10

Generated at Wed, 16 Apr 2014 12:47:50 +0000 (3 days ago)

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