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: 470 522 90.0 %
Date: 2014-07-21 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         166 : int php_le_pmysqli(void)
     113             : {
     114         166 :         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        1420 : void php_clear_mysql(MY_MYSQL *mysql) {
     193        1420 :         if (mysql->hash_key) {
     194          81 :                 efree(mysql->hash_key);
     195          81 :                 mysql->hash_key = NULL;
     196             :         }
     197        1420 :         if (mysql->li_read) {
     198           0 :                 zval_ptr_dtor(&(mysql->li_read));
     199           0 :                 mysql->li_read = NULL;
     200             :         }
     201        1420 : }
     202             : /* }}} */
     203             : 
     204             : /* {{{ mysqli_objects_free_storage
     205             :  */
     206        5729 : static void mysqli_objects_free_storage(void *object TSRMLS_DC)
     207             : {
     208        5729 :         zend_object *zo = (zend_object *)object;
     209        5729 :         mysqli_object   *intern = (mysqli_object *)zo;
     210        5729 :         MYSQLI_RESOURCE *my_res = (MYSQLI_RESOURCE *)intern->ptr;
     211             : 
     212        5729 :         my_efree(my_res);
     213        5729 :         zend_object_std_dtor(&intern->zo TSRMLS_CC);
     214        5729 :         efree(intern);
     215        5729 : }
     216             : /* }}} */
     217             : 
     218             : /* mysqli_link_free_storage partly doubles the work of PHP_FUNCTION(mysqli_close) */
     219             : 
     220             : /* {{{ mysqli_link_free_storage
     221             :  */
     222        1226 : static void mysqli_link_free_storage(void *object TSRMLS_DC)
     223             : {
     224        1226 :         zend_object *zo = (zend_object *)object;
     225        1226 :         mysqli_object   *intern = (mysqli_object *)zo;
     226        1226 :         MYSQLI_RESOURCE *my_res = (MYSQLI_RESOURCE *)intern->ptr;
     227             : 
     228        1226 :         if (my_res && my_res->ptr) {
     229         182 :                 MY_MYSQL *mysql = (MY_MYSQL *)my_res->ptr;
     230         182 :                 if (mysql->mysql) {
     231         182 :                         php_mysqli_close(mysql, MYSQLI_CLOSE_EXPLICIT, my_res->status TSRMLS_CC);
     232             :                 }
     233         182 :                 php_clear_mysql(mysql);
     234         182 :                 efree(mysql);
     235         182 :                 my_res->status = MYSQLI_STATUS_UNKNOWN;
     236             :         }
     237        1226 :         mysqli_objects_free_storage(object TSRMLS_CC);
     238        1226 : }
     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        2388 : static void mysqli_result_free_storage(void *object TSRMLS_DC)
     267             : {
     268        2388 :         zend_object *zo = (zend_object *)object;
     269        2388 :         mysqli_object   *intern = (mysqli_object *)zo;
     270        2388 :         MYSQLI_RESOURCE *my_res = (MYSQLI_RESOURCE *)intern->ptr;
     271             : 
     272        2388 :         if (my_res && my_res->ptr) {
     273        1135 :                 mysql_free_result(my_res->ptr);
     274             :         }
     275        2388 :         mysqli_objects_free_storage(object TSRMLS_CC);
     276        2388 : }
     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      914051 : 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      914051 :         p.name = (char*) pname;
     406      914051 :         p.name_len = pname_len;
     407      914051 :         p.read_func = (r_func) ? r_func : mysqli_read_na;
     408      914051 :         p.write_func = (w_func) ? w_func : mysqli_write_na;
     409      914051 :         zend_hash_add(h, pname, pname_len + 1, &p, sizeof(mysqli_prop_handler), NULL);
     410      914051 : }
     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        5723 : 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        5723 :         intern = emalloc(sizeof(mysqli_object));
     496        5723 :         memset(intern, 0, sizeof(mysqli_object));
     497        5723 :         intern->ptr = NULL;
     498        5723 :         intern->prop_handler = NULL;
     499             : 
     500        5723 :         mysqli_base_class = class_type;
     501       11554 :         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        5723 :         zend_hash_find(&classes, mysqli_base_class->name, mysqli_base_class->name_length + 1,
     506        5723 :                                         (void **) &intern->prop_handler);
     507             : 
     508        5723 :         zend_object_std_init(&intern->zo, class_type TSRMLS_CC);
     509        5723 :         object_properties_init(&intern->zo, class_type);
     510             : 
     511             :         /* link object */
     512        5723 :         if (instanceof_function(class_type, mysqli_link_class_entry TSRMLS_CC)) {
     513        1224 :                 free_storage = mysqli_link_free_storage;
     514        4499 :         } else if (instanceof_function(class_type, mysqli_driver_class_entry TSRMLS_CC)) { /* driver object */
     515        1160 :                 free_storage = mysqli_driver_free_storage;
     516        3339 :         } else if (instanceof_function(class_type, mysqli_stmt_class_entry TSRMLS_CC)) { /* stmt object */
     517         947 :                 free_storage = mysqli_stmt_free_storage;
     518        2392 :         } else if (instanceof_function(class_type, mysqli_result_class_entry TSRMLS_CC)) { /* result object */
     519        2386 :                 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        5723 :         retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, free_storage, NULL TSRMLS_CC);
     527        5723 :         retval.handlers = &mysqli_object_handlers;
     528             : 
     529        5723 :         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       21257 : static PHP_GINIT_FUNCTION(mysqli)
     583             : {
     584       21257 :         mysqli_globals->num_links = 0;
     585       21257 :         mysqli_globals->num_active_persistent = 0;
     586       21257 :         mysqli_globals->num_inactive_persistent = 0;
     587       21257 :         mysqli_globals->max_links = -1;
     588       21257 :         mysqli_globals->max_persistent = -1;
     589       21257 :         mysqli_globals->allow_persistent = 1;
     590       21257 :         mysqli_globals->default_port = 0;
     591       21257 :         mysqli_globals->default_host = NULL;
     592       21257 :         mysqli_globals->default_user = NULL;
     593       21257 :         mysqli_globals->default_pw = NULL;
     594       21257 :         mysqli_globals->default_socket = NULL;
     595       21257 :         mysqli_globals->reconnect = 0;
     596       21257 :         mysqli_globals->report_mode = 0;
     597       21257 :         mysqli_globals->report_ht = 0;
     598       21257 :         mysqli_globals->allow_local_infile = 1;
     599             : #ifdef HAVE_EMBEDDED_MYSQLI
     600             :         mysqli_globals->embedded = 1;
     601             : #else
     602       21257 :         mysqli_globals->embedded = 0;
     603             : #endif
     604       21257 :         mysqli_globals->rollback_on_cached_plink = FALSE;
     605       21257 : }
     606             : /* }}} */
     607             : 
     608             : /* {{{ PHP_MINIT_FUNCTION
     609             :  */
     610       21257 : PHP_MINIT_FUNCTION(mysqli)
     611             : {
     612             :         zend_class_entry *ce,cex;
     613       21257 :         zend_object_handlers *std_hnd = zend_get_std_object_handlers();
     614             : 
     615       21257 :         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       21257 :         memcpy(&mysqli_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
     625       21257 :         mysqli_object_handlers.clone_obj = NULL;
     626       21257 :         mysqli_object_handlers.read_property = mysqli_read_property;
     627       21257 :         mysqli_object_handlers.write_property = mysqli_write_property;
     628       21257 :         mysqli_object_handlers.get_property_ptr_ptr = std_hnd->get_property_ptr_ptr;
     629       21257 :         mysqli_object_handlers.has_property = mysqli_object_has_property;
     630             : #if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3
     631       21257 :         mysqli_object_handlers.get_debug_info = mysqli_object_get_debug_info;
     632             : #endif
     633             : 
     634       21257 :         zend_hash_init(&classes, 0, NULL, NULL, 1);
     635             : 
     636             :         /* persistent connections */
     637       21257 :         le_pmysqli = zend_register_list_destructors_ex(NULL, php_mysqli_dtor,
     638             :                 "MySqli persistent connection", module_number);
     639             : 
     640       21257 :         INIT_CLASS_ENTRY(cex, "mysqli_sql_exception", mysqli_exception_methods);
     641             : #ifdef HAVE_SPL
     642       21257 :         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       21257 :         mysqli_exception_class_entry->ce_flags |= ZEND_ACC_FINAL;
     647       21257 :         zend_declare_property_long(mysqli_exception_class_entry, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED TSRMLS_CC);
     648       21257 :         zend_declare_property_string(mysqli_exception_class_entry, "sqlstate", sizeof("sqlstate")-1, "00000", ZEND_ACC_PROTECTED TSRMLS_CC);
     649             : 
     650       21257 :         REGISTER_MYSQLI_CLASS_ENTRY("mysqli_driver", mysqli_driver_class_entry, mysqli_driver_methods);
     651       21257 :         ce = mysqli_driver_class_entry;
     652       21257 :         zend_hash_init(&mysqli_driver_properties, 0, NULL, NULL, 1);
     653       21257 :         MYSQLI_ADD_PROPERTIES(&mysqli_driver_properties, mysqli_driver_property_entries);
     654       21257 :         MYSQLI_ADD_PROPERTIES_INFO(ce, mysqli_driver_property_info_entries);
     655       21257 :         zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_driver_properties, sizeof(mysqli_driver_properties), NULL);
     656       21257 :         ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
     657             : 
     658       21257 :         REGISTER_MYSQLI_CLASS_ENTRY("mysqli", mysqli_link_class_entry, mysqli_link_methods);
     659       21257 :         ce = mysqli_link_class_entry;
     660       21257 :         zend_hash_init(&mysqli_link_properties, 0, NULL, NULL, 1);
     661       21257 :         MYSQLI_ADD_PROPERTIES(&mysqli_link_properties, mysqli_link_property_entries);
     662       21257 :         MYSQLI_ADD_PROPERTIES_INFO(ce, mysqli_link_property_info_entries);
     663       21257 :         zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_link_properties, sizeof(mysqli_link_properties), NULL);
     664             : 
     665       21257 :         REGISTER_MYSQLI_CLASS_ENTRY("mysqli_warning", mysqli_warning_class_entry, mysqli_warning_methods);
     666       21257 :         ce = mysqli_warning_class_entry;
     667       21257 :         ce->ce_flags |= ZEND_ACC_FINAL_CLASS | ZEND_ACC_PROTECTED;
     668       21257 :         zend_hash_init(&mysqli_warning_properties, 0, NULL, NULL, 1);
     669       21257 :         MYSQLI_ADD_PROPERTIES(&mysqli_warning_properties, mysqli_warning_property_entries);
     670       21257 :         MYSQLI_ADD_PROPERTIES_INFO(ce, mysqli_warning_property_info_entries);
     671       21257 :         zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_warning_properties, sizeof(mysqli_warning_properties), NULL);
     672             : 
     673       21257 :         REGISTER_MYSQLI_CLASS_ENTRY("mysqli_result", mysqli_result_class_entry, mysqli_result_methods);
     674       21257 :         ce = mysqli_result_class_entry;
     675       21257 :         zend_hash_init(&mysqli_result_properties, 0, NULL, NULL, 1);
     676       21257 :         MYSQLI_ADD_PROPERTIES(&mysqli_result_properties, mysqli_result_property_entries);
     677       21257 :         MYSQLI_ADD_PROPERTIES_INFO(ce, mysqli_result_property_info_entries);
     678       21257 :         mysqli_result_class_entry->get_iterator = php_mysqli_result_get_iterator;
     679       21257 :         mysqli_result_class_entry->iterator_funcs.funcs = &php_mysqli_result_iterator_funcs;
     680       21257 :         zend_class_implements(mysqli_result_class_entry TSRMLS_CC, 1, zend_ce_traversable);
     681       21257 :         zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_result_properties, sizeof(mysqli_result_properties), NULL);
     682             : 
     683       21257 :         REGISTER_MYSQLI_CLASS_ENTRY("mysqli_stmt", mysqli_stmt_class_entry, mysqli_stmt_methods);
     684       21257 :         ce = mysqli_stmt_class_entry;
     685       21257 :         zend_hash_init(&mysqli_stmt_properties, 0, NULL, NULL, 1);
     686       21257 :         MYSQLI_ADD_PROPERTIES(&mysqli_stmt_properties, mysqli_stmt_property_entries);
     687       21257 :         MYSQLI_ADD_PROPERTIES_INFO(ce, mysqli_stmt_property_info_entries);
     688       21257 :         zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_stmt_properties, sizeof(mysqli_stmt_properties), NULL);
     689             : 
     690             :         /* mysqli_options */
     691       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_READ_DEFAULT_GROUP", MYSQL_READ_DEFAULT_GROUP, CONST_CS | CONST_PERSISTENT);
     692       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_READ_DEFAULT_FILE", MYSQL_READ_DEFAULT_FILE, CONST_CS | CONST_PERSISTENT);
     693       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_OPT_CONNECT_TIMEOUT", MYSQL_OPT_CONNECT_TIMEOUT, CONST_CS | CONST_PERSISTENT);
     694       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_OPT_LOCAL_INFILE", MYSQL_OPT_LOCAL_INFILE, CONST_CS | CONST_PERSISTENT);
     695       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_INIT_COMMAND", MYSQL_INIT_COMMAND, CONST_CS | CONST_PERSISTENT);
     696             : #if defined(MYSQLI_USE_MYSQLND)
     697       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_OPT_NET_CMD_BUFFER_SIZE", MYSQLND_OPT_NET_CMD_BUFFER_SIZE, CONST_CS | CONST_PERSISTENT);
     698       21257 :         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       21257 :         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       21257 :         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       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_SERVER_PUBLIC_KEY", MYSQL_SERVER_PUBLIC_KEY, CONST_CS | CONST_PERSISTENT);
     709             : #endif
     710             : 
     711             :         /* mysqli_real_connect flags */
     712       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_CLIENT_SSL", CLIENT_SSL, CONST_CS | CONST_PERSISTENT);
     713       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_CLIENT_COMPRESS",CLIENT_COMPRESS, CONST_CS | CONST_PERSISTENT);
     714       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_CLIENT_INTERACTIVE", CLIENT_INTERACTIVE, CONST_CS | CONST_PERSISTENT);
     715       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_CLIENT_IGNORE_SPACE", CLIENT_IGNORE_SPACE, CONST_CS | CONST_PERSISTENT);
     716       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_CLIENT_NO_SCHEMA", CLIENT_NO_SCHEMA, CONST_CS | CONST_PERSISTENT);
     717       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_CLIENT_FOUND_ROWS", CLIENT_FOUND_ROWS, CONST_CS | CONST_PERSISTENT);
     718             : #if (MYSQL_VERSION_ID >= 50611 && defined(CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS)) || defined(MYSQLI_USE_MYSQLND)
     719       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS", CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS, CONST_CS | CONST_PERSISTENT);
     720       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_OPT_CAN_HANDLE_EXPIRED_PASSWORDS", MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, CONST_CS | CONST_PERSISTENT);
     721             : #endif
     722             : 
     723             :         /* for mysqli_query */
     724       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_STORE_RESULT", MYSQLI_STORE_RESULT, CONST_CS | CONST_PERSISTENT);
     725       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_USE_RESULT", MYSQLI_USE_RESULT, CONST_CS | CONST_PERSISTENT);
     726             : #if defined (MYSQLI_USE_MYSQLND)
     727       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_ASYNC", MYSQLI_ASYNC, CONST_CS | CONST_PERSISTENT);
     728       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_STORE_RESULT_COPY_DATA", MYSQLI_STORE_RESULT_COPY_DATA, CONST_CS | CONST_PERSISTENT);
     729             : #endif
     730             : 
     731             :         /* for mysqli_fetch_assoc */
     732       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_ASSOC", MYSQLI_ASSOC, CONST_CS | CONST_PERSISTENT);
     733       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_NUM", MYSQLI_NUM, CONST_CS | CONST_PERSISTENT);
     734       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_BOTH", MYSQLI_BOTH, CONST_CS | CONST_PERSISTENT);
     735             : 
     736             :         /* for mysqli_stmt_set_attr */
     737       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH", STMT_ATTR_UPDATE_MAX_LENGTH, CONST_CS | CONST_PERSISTENT);
     738             : 
     739             : #if MYSQL_VERSION_ID > 50003 || defined(MYSQLI_USE_MYSQLND)
     740       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_STMT_ATTR_CURSOR_TYPE", STMT_ATTR_CURSOR_TYPE, CONST_CS | CONST_PERSISTENT);
     741       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_CURSOR_TYPE_NO_CURSOR", CURSOR_TYPE_NO_CURSOR, CONST_CS | CONST_PERSISTENT);
     742       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_CURSOR_TYPE_READ_ONLY", CURSOR_TYPE_READ_ONLY, CONST_CS | CONST_PERSISTENT);
     743       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_CURSOR_TYPE_FOR_UPDATE", CURSOR_TYPE_FOR_UPDATE, CONST_CS | CONST_PERSISTENT);
     744       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_CURSOR_TYPE_SCROLLABLE", CURSOR_TYPE_SCROLLABLE, CONST_CS | CONST_PERSISTENT);
     745             : #endif
     746             : 
     747             : #if MYSQL_VERSION_ID > 50007 || defined(MYSQLI_USE_MYSQLND)
     748       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_STMT_ATTR_PREFETCH_ROWS", STMT_ATTR_PREFETCH_ROWS, CONST_CS | CONST_PERSISTENT);
     749             : #endif
     750             : 
     751             :         /* column information */
     752       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_NOT_NULL_FLAG", NOT_NULL_FLAG, CONST_CS | CONST_PERSISTENT);
     753       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_PRI_KEY_FLAG", PRI_KEY_FLAG, CONST_CS | CONST_PERSISTENT);
     754       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_UNIQUE_KEY_FLAG", UNIQUE_KEY_FLAG, CONST_CS | CONST_PERSISTENT);
     755       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_MULTIPLE_KEY_FLAG", MULTIPLE_KEY_FLAG, CONST_CS | CONST_PERSISTENT);
     756       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_BLOB_FLAG", BLOB_FLAG, CONST_CS | CONST_PERSISTENT);
     757       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_UNSIGNED_FLAG", UNSIGNED_FLAG, CONST_CS | CONST_PERSISTENT);
     758       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_ZEROFILL_FLAG", ZEROFILL_FLAG, CONST_CS | CONST_PERSISTENT);
     759       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_AUTO_INCREMENT_FLAG", AUTO_INCREMENT_FLAG, CONST_CS | CONST_PERSISTENT);
     760       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TIMESTAMP_FLAG", TIMESTAMP_FLAG, CONST_CS | CONST_PERSISTENT);
     761       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_SET_FLAG", SET_FLAG, CONST_CS | CONST_PERSISTENT);
     762       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_NUM_FLAG", NUM_FLAG, CONST_CS | CONST_PERSISTENT);
     763       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_PART_KEY_FLAG", PART_KEY_FLAG, CONST_CS | CONST_PERSISTENT);
     764       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_GROUP_FLAG", GROUP_FLAG, CONST_CS | CONST_PERSISTENT);
     765       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_ENUM_FLAG", ENUM_FLAG, CONST_CS | CONST_PERSISTENT);
     766       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_BINARY_FLAG", BINARY_FLAG, CONST_CS | CONST_PERSISTENT);
     767             : #if MYSQL_VERSION_ID > 50001 || defined(MYSQLI_USE_MYSQLND)
     768       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_NO_DEFAULT_VALUE_FLAG", NO_DEFAULT_VALUE_FLAG, CONST_CS | CONST_PERSISTENT);
     769             : #endif
     770             : 
     771             : #if (MYSQL_VERSION_ID > 51122 && MYSQL_VERSION_ID < 60000) || (MYSQL_VERSION_ID > 60003) || defined(MYSQLI_USE_MYSQLND)
     772       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_ON_UPDATE_NOW_FLAG", ON_UPDATE_NOW_FLAG, CONST_CS | CONST_PERSISTENT);
     773             : #endif
     774             : 
     775       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_DECIMAL", FIELD_TYPE_DECIMAL, CONST_CS | CONST_PERSISTENT);
     776       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_TINY", FIELD_TYPE_TINY, CONST_CS | CONST_PERSISTENT);
     777       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_SHORT", FIELD_TYPE_SHORT, CONST_CS | CONST_PERSISTENT);
     778       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_LONG", FIELD_TYPE_LONG, CONST_CS | CONST_PERSISTENT);
     779       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_FLOAT", FIELD_TYPE_FLOAT, CONST_CS | CONST_PERSISTENT);
     780       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_DOUBLE", FIELD_TYPE_DOUBLE, CONST_CS | CONST_PERSISTENT);
     781       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_NULL", FIELD_TYPE_NULL, CONST_CS | CONST_PERSISTENT);
     782       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_TIMESTAMP", FIELD_TYPE_TIMESTAMP, CONST_CS | CONST_PERSISTENT);
     783       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_LONGLONG", FIELD_TYPE_LONGLONG, CONST_CS | CONST_PERSISTENT);
     784       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_INT24", FIELD_TYPE_INT24, CONST_CS | CONST_PERSISTENT);
     785       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_DATE", FIELD_TYPE_DATE, CONST_CS | CONST_PERSISTENT);
     786       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_TIME", FIELD_TYPE_TIME, CONST_CS | CONST_PERSISTENT);
     787       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_DATETIME", FIELD_TYPE_DATETIME    , CONST_CS | CONST_PERSISTENT);
     788       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_YEAR", FIELD_TYPE_YEAR, CONST_CS | CONST_PERSISTENT);
     789       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_NEWDATE", FIELD_TYPE_NEWDATE, CONST_CS | CONST_PERSISTENT);
     790       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_ENUM", FIELD_TYPE_ENUM, CONST_CS | CONST_PERSISTENT);
     791       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_SET", FIELD_TYPE_SET, CONST_CS | CONST_PERSISTENT);
     792       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_TINY_BLOB", FIELD_TYPE_TINY_BLOB, CONST_CS | CONST_PERSISTENT);
     793       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_MEDIUM_BLOB", FIELD_TYPE_MEDIUM_BLOB, CONST_CS | CONST_PERSISTENT);
     794       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_LONG_BLOB", FIELD_TYPE_LONG_BLOB, CONST_CS | CONST_PERSISTENT);
     795       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_BLOB", FIELD_TYPE_BLOB, CONST_CS | CONST_PERSISTENT);
     796       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_VAR_STRING", FIELD_TYPE_VAR_STRING, CONST_CS | CONST_PERSISTENT);
     797       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_STRING", FIELD_TYPE_STRING, CONST_CS | CONST_PERSISTENT);
     798       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_CHAR", FIELD_TYPE_CHAR, CONST_CS | CONST_PERSISTENT);
     799       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_INTERVAL", FIELD_TYPE_INTERVAL, CONST_CS | CONST_PERSISTENT);
     800       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_GEOMETRY", FIELD_TYPE_GEOMETRY, CONST_CS | CONST_PERSISTENT);
     801             : 
     802             : #if MYSQL_VERSION_ID > 50002 || defined(MYSQLI_USE_MYSQLND)
     803       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_NEWDECIMAL", FIELD_TYPE_NEWDECIMAL, CONST_CS | CONST_PERSISTENT);
     804       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TYPE_BIT", FIELD_TYPE_BIT, CONST_CS | CONST_PERSISTENT);
     805             : #endif
     806             : 
     807       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_SET_CHARSET_NAME", MYSQL_SET_CHARSET_NAME, CONST_CS | CONST_PERSISTENT);
     808       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_SET_CHARSET_DIR", MYSQL_SET_CHARSET_DIR, CONST_CS | CONST_PERSISTENT);
     809             : 
     810             :         /* bind support */
     811       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_NO_DATA", MYSQL_NO_DATA, CONST_CS | CONST_PERSISTENT);
     812             : #ifdef MYSQL_DATA_TRUNCATED
     813       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_DATA_TRUNCATED", MYSQL_DATA_TRUNCATED, CONST_CS | CONST_PERSISTENT);
     814             : #endif
     815             : 
     816             :         /* reporting */
     817       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_REPORT_INDEX", MYSQLI_REPORT_INDEX, CONST_CS | CONST_PERSISTENT);
     818       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_REPORT_ERROR", MYSQLI_REPORT_ERROR, CONST_CS | CONST_PERSISTENT);
     819       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_REPORT_STRICT", MYSQLI_REPORT_STRICT, CONST_CS | CONST_PERSISTENT);
     820       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_REPORT_ALL", MYSQLI_REPORT_ALL, CONST_CS | CONST_PERSISTENT);
     821       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_REPORT_OFF", 0, CONST_CS | CONST_PERSISTENT);
     822             : 
     823             :         /* We use non-nested macros with expansion, as VC has problems */
     824             : #ifdef MYSQLI_USE_MYSQLND
     825       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_DEBUG_TRACE_ENABLED", MYSQLND_DBG_ENABLED, CONST_CS | CONST_PERSISTENT);
     826             : #else
     827             : #ifdef DBUG_ON
     828             :         REGISTER_LONG_CONSTANT("MYSQLI_DEBUG_TRACE_ENABLED", 1, CONST_CS | CONST_PERSISTENT);
     829             : #else
     830             :         REGISTER_LONG_CONSTANT("MYSQLI_DEBUG_TRACE_ENABLED", 0, CONST_CS | CONST_PERSISTENT);
     831             : #endif
     832             : #endif
     833             : 
     834       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_SERVER_QUERY_NO_GOOD_INDEX_USED", SERVER_QUERY_NO_GOOD_INDEX_USED, CONST_CS | CONST_PERSISTENT);
     835       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_SERVER_QUERY_NO_INDEX_USED", SERVER_QUERY_NO_INDEX_USED, CONST_CS | CONST_PERSISTENT);
     836             : #ifdef SERVER_QUERY_WAS_SLOW
     837       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_SERVER_QUERY_WAS_SLOW", SERVER_QUERY_WAS_SLOW, CONST_CS | CONST_PERSISTENT);
     838             : #endif
     839             : #ifdef SERVER_PS_OUT_PARAMS
     840       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_SERVER_PS_OUT_PARAMS", SERVER_PS_OUT_PARAMS, CONST_CS | CONST_PERSISTENT);
     841             : #endif
     842             : 
     843       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_REFRESH_GRANT",      REFRESH_GRANT, CONST_CS | CONST_PERSISTENT);
     844       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_REFRESH_LOG",        REFRESH_LOG, CONST_CS | CONST_PERSISTENT);
     845       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_REFRESH_TABLES",     REFRESH_TABLES, CONST_CS | CONST_PERSISTENT);
     846       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_REFRESH_HOSTS",      REFRESH_HOSTS, CONST_CS | CONST_PERSISTENT);
     847       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_REFRESH_STATUS",     REFRESH_STATUS, CONST_CS | CONST_PERSISTENT);
     848       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_REFRESH_THREADS",    REFRESH_THREADS, CONST_CS | CONST_PERSISTENT);
     849       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_REFRESH_SLAVE",      REFRESH_SLAVE, CONST_CS | CONST_PERSISTENT);
     850       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_REFRESH_MASTER",     REFRESH_MASTER, CONST_CS | CONST_PERSISTENT);
     851             : #ifdef REFRESH_BACKUP_LOG
     852       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_REFRESH_BACKUP_LOG", REFRESH_BACKUP_LOG, CONST_CS | CONST_PERSISTENT);
     853             : #endif
     854             : 
     855             : 
     856       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TRANS_START_WITH_CONSISTENT_SNAPSHOT", TRANS_START_WITH_CONSISTENT_SNAPSHOT, CONST_CS | CONST_PERSISTENT);
     857       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TRANS_START_READ_WRITE", TRANS_START_READ_WRITE, CONST_CS | CONST_PERSISTENT);
     858       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TRANS_START_READ_ONLY", TRANS_START_READ_ONLY, CONST_CS | CONST_PERSISTENT);
     859             : 
     860       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TRANS_COR_AND_CHAIN", TRANS_COR_AND_CHAIN, CONST_CS | CONST_PERSISTENT);
     861       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TRANS_COR_AND_NO_CHAIN", TRANS_COR_AND_NO_CHAIN, CONST_CS | CONST_PERSISTENT);
     862       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TRANS_COR_RELEASE", TRANS_COR_RELEASE, CONST_CS | CONST_PERSISTENT);
     863       21257 :         REGISTER_LONG_CONSTANT("MYSQLI_TRANS_COR_NO_RELEASE", TRANS_COR_NO_RELEASE, CONST_CS | CONST_PERSISTENT);
     864             : 
     865             : 
     866             : #ifdef MYSQLI_USE_MYSQLND
     867       21257 :         mysqlnd_reverse_api_register_api(&mysqli_reverse_api TSRMLS_CC);
     868             : #endif
     869             : 
     870       21257 :         return SUCCESS;
     871             : }
     872             : /* }}} */
     873             : 
     874             : /* {{{ PHP_MSHUTDOWN_FUNCTION
     875             :  */
     876       21290 : PHP_MSHUTDOWN_FUNCTION(mysqli)
     877             : {
     878             : #ifndef MYSQLI_USE_MYSQLND
     879             : #if MYSQL_VERSION_ID >= 40000
     880             : #ifdef PHP_WIN32
     881             :         unsigned long client_ver = mysql_get_client_version();
     882             :         /*
     883             :           Can't call mysql_server_end() multiple times prior to 5.0.46 on Windows.
     884             :           PHP bug#41350 MySQL bug#25621
     885             :         */
     886             :         if ((client_ver >= 50046 && client_ver < 50100) || client_ver > 50122) {
     887             :                 mysql_server_end();
     888             :         }
     889             : #else
     890             :         mysql_server_end();
     891             : #endif
     892             : #endif
     893             : #endif
     894             : 
     895       21290 :         zend_hash_destroy(&mysqli_driver_properties);
     896       21290 :         zend_hash_destroy(&mysqli_result_properties);
     897       21290 :         zend_hash_destroy(&mysqli_stmt_properties);
     898       21290 :         zend_hash_destroy(&mysqli_warning_properties);
     899       21290 :         zend_hash_destroy(&mysqli_link_properties);
     900       21290 :         zend_hash_destroy(&classes);
     901             : 
     902       21290 :         UNREGISTER_INI_ENTRIES();
     903       21290 :         return SUCCESS;
     904             : }
     905             : /* }}} */
     906             : 
     907             : /* {{{ PHP_RINIT_FUNCTION
     908             :  */
     909       21214 : PHP_RINIT_FUNCTION(mysqli)
     910             : {
     911             : #if !defined(MYSQLI_USE_MYSQLND) && defined(ZTS) && MYSQL_VERSION_ID >= 40000
     912             :         if (mysql_thread_init()) {
     913             :                 return FAILURE;
     914             :         }
     915             : #endif
     916       21214 :         MyG(error_msg) = NULL;
     917       21214 :         MyG(error_no) = 0;
     918       21214 :         MyG(report_mode) = 0;
     919             : 
     920       21214 :         return SUCCESS;
     921             : }
     922             : /* }}} */
     923             : 
     924             : #if defined(A0) && defined(MYSQLI_USE_MYSQLND)
     925             : static void php_mysqli_persistent_helper_for_every(void *p)
     926             : {
     927             :         TSRMLS_FETCH();
     928             :         mysqlnd_end_psession((MYSQLND *) p);
     929             : } /* }}} */
     930             : 
     931             : 
     932             : static int php_mysqli_persistent_helper_once(zend_rsrc_list_entry *le TSRMLS_DC)
     933             : {
     934             :         if (le->type == php_le_pmysqli()) {
     935             :                 mysqli_plist_entry *plist = (mysqli_plist_entry *) le->ptr;
     936             :                 zend_ptr_stack_apply(&plist->free_links, php_mysqli_persistent_helper_for_every);
     937             :         }
     938             :         return ZEND_HASH_APPLY_KEEP;
     939             : } /* }}} */
     940             : #endif
     941             : 
     942             : 
     943             : /* {{{ PHP_RSHUTDOWN_FUNCTION
     944             :  */
     945       21249 : PHP_RSHUTDOWN_FUNCTION(mysqli)
     946             : {
     947             :         /* check persistent connections, move used to free */
     948             : 
     949             : #if !defined(MYSQLI_USE_MYSQLND) && defined(ZTS) && MYSQL_VERSION_ID >= 40000
     950             :         mysql_thread_end();
     951             : #endif
     952       21249 :         if (MyG(error_msg)) {
     953           8 :                 efree(MyG(error_msg));
     954             :         }
     955             : #if defined(A0) && defined(MYSQLI_USE_MYSQLND)
     956             :         /* psession is being called when the connection is freed - explicitly or implicitly */
     957             :         zend_hash_apply(&EG(persistent_list), (apply_func_t) php_mysqli_persistent_helper_once TSRMLS_CC);
     958             : #endif
     959       21249 :         return SUCCESS;
     960             : }
     961             : /* }}} */
     962             : 
     963             : 
     964             : /* {{{ PHP_MINFO_FUNCTION
     965             :  */
     966         150 : PHP_MINFO_FUNCTION(mysqli)
     967             : {
     968             :         char buf[32];
     969             : 
     970         150 :         php_info_print_table_start();
     971         150 :         php_info_print_table_header(2, "MysqlI Support", "enabled");
     972         150 :         php_info_print_table_row(2, "Client API library version", mysql_get_client_info());
     973         150 :         snprintf(buf, sizeof(buf), "%ld", MyG(num_active_persistent));
     974         150 :         php_info_print_table_row(2, "Active Persistent Links", buf);
     975         150 :         snprintf(buf, sizeof(buf), "%ld", MyG(num_inactive_persistent));
     976         150 :         php_info_print_table_row(2, "Inactive Persistent Links", buf);
     977         150 :         snprintf(buf, sizeof(buf), "%ld", MyG(num_links));
     978         150 :         php_info_print_table_row(2, "Active Links", buf);
     979             : #if !defined(MYSQLI_USE_MYSQLND)
     980             :         php_info_print_table_row(2, "Client API header version", MYSQL_SERVER_VERSION);
     981             :         php_info_print_table_row(2, "MYSQLI_SOCKET", MYSQL_UNIX_ADDR);
     982             : #endif
     983         150 :         php_info_print_table_end();
     984             : 
     985         150 :         DISPLAY_INI_ENTRIES();
     986         150 : }
     987             : /* }}} */
     988             : 
     989             : 
     990             : /* Dependancies */
     991             : static const  zend_module_dep mysqli_deps[] = {
     992             : #if defined(HAVE_SPL) && ((PHP_MAJOR_VERSION > 5) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1))
     993             :         ZEND_MOD_REQUIRED("spl")
     994             : #endif
     995             : #if defined(MYSQLI_USE_MYSQLND)
     996             :         ZEND_MOD_REQUIRED("mysqlnd")
     997             : #endif
     998             :         ZEND_MOD_END
     999             : };
    1000             : 
    1001             : /* {{{ mysqli_module_entry
    1002             :  */
    1003             : zend_module_entry mysqli_module_entry = {
    1004             : #if ZEND_MODULE_API_NO >= 20050922
    1005             :         STANDARD_MODULE_HEADER_EX, NULL,
    1006             :         mysqli_deps,
    1007             : #elif ZEND_MODULE_API_NO >= 20010901
    1008             :         STANDARD_MODULE_HEADER,
    1009             : #endif
    1010             :         "mysqli",
    1011             :         mysqli_functions,
    1012             :         PHP_MINIT(mysqli),
    1013             :         PHP_MSHUTDOWN(mysqli),
    1014             :         PHP_RINIT(mysqli),
    1015             :         PHP_RSHUTDOWN(mysqli),
    1016             :         PHP_MINFO(mysqli),
    1017             :         "0.1", /* Replace with version number for your extension */
    1018             :         PHP_MODULE_GLOBALS(mysqli),
    1019             :         PHP_GINIT(mysqli),
    1020             :         NULL,
    1021             :         NULL,
    1022             :         STANDARD_MODULE_PROPERTIES_EX
    1023             : };
    1024             : /* }}} */
    1025             : 
    1026             : #ifdef COMPILE_DL_MYSQLI
    1027             : ZEND_GET_MODULE(mysqli)
    1028             : #endif
    1029             : 
    1030             : 
    1031             : /* {{{ mixed mysqli_stmt_construct()
    1032             : constructor for statement object.
    1033             : Parameters:
    1034             :   object -> mysqli_stmt_init
    1035             :   object, query -> mysqli_prepare
    1036             : */
    1037           8 : PHP_FUNCTION(mysqli_stmt_construct)
    1038             : {
    1039             :         MY_MYSQL                        *mysql;
    1040             :         zval                            *mysql_link;
    1041             :         MY_STMT                         *stmt;
    1042             :         MYSQLI_RESOURCE         *mysqli_resource;
    1043             :         char                            *statement;
    1044             :         int                                     statement_len;
    1045             : 
    1046           8 :         switch (ZEND_NUM_ARGS())
    1047             :         {
    1048             :                 case 1:  /* mysql_stmt_init */
    1049           2 :                         if (zend_parse_parameters(1 TSRMLS_CC, "O", &mysql_link, mysqli_link_class_entry)==FAILURE) {
    1050           1 :                                 return;
    1051             :                         }
    1052           1 :                         MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
    1053             : 
    1054           1 :                         stmt = (MY_STMT *)ecalloc(1,sizeof(MY_STMT));
    1055             : 
    1056           1 :                         stmt->stmt = mysql_stmt_init(mysql->mysql);
    1057           1 :                 break;
    1058             :                 case 2:
    1059           5 :                         if (zend_parse_parameters(2 TSRMLS_CC, "Os", &mysql_link, mysqli_link_class_entry, &statement, &statement_len)==FAILURE) {
    1060           1 :                                 return;
    1061             :                         }
    1062           4 :                         MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
    1063             : 
    1064           4 :                         stmt = (MY_STMT *)ecalloc(1,sizeof(MY_STMT));
    1065             : 
    1066           4 :                         if ((stmt->stmt = mysql_stmt_init(mysql->mysql))) {
    1067           4 :                                 mysql_stmt_prepare(stmt->stmt, (char *)statement, statement_len);
    1068             :                         }
    1069           4 :                 break;
    1070             :                 default:
    1071           1 :                         WRONG_PARAM_COUNT;
    1072             :                 break;
    1073             :         }
    1074             : 
    1075           5 :         if (!stmt->stmt) {
    1076           0 :                 efree(stmt);
    1077           0 :                 RETURN_FALSE;
    1078             :         }
    1079             : #ifndef MYSQLI_USE_MYSQLND
    1080             :         stmt->link_handle = Z_OBJ_HANDLE(*mysql_link);
    1081             :         zend_objects_store_add_ref_by_handle(stmt->link_handle TSRMLS_CC);
    1082             : #endif
    1083             : 
    1084           5 :         mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
    1085           5 :         mysqli_resource->ptr = (void *)stmt;
    1086           5 :         mysqli_resource->status = (ZEND_NUM_ARGS() == 1) ? MYSQLI_STATUS_INITIALIZED : MYSQLI_STATUS_VALID;
    1087             : 
    1088           5 :         ((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->ptr = mysqli_resource;
    1089             : }
    1090             : /* }}} */
    1091             : 
    1092             : /* {{{ mixed mysqli_result_construct()
    1093             : constructor for result object.
    1094             : Parameters:
    1095             :   object [, mode] -> mysqli_store/use_result
    1096             : */
    1097          15 : PHP_FUNCTION(mysqli_result_construct)
    1098             : {
    1099             :         MY_MYSQL                        *mysql;
    1100          15 :         MYSQL_RES                       *result = NULL;
    1101             :         zval                            *mysql_link;
    1102             :         MYSQLI_RESOURCE         *mysqli_resource;
    1103          15 :         long                            resmode = MYSQLI_STORE_RESULT;
    1104             : 
    1105          15 :         switch (ZEND_NUM_ARGS()) {
    1106             :                 case 1:
    1107           9 :                         if (zend_parse_parameters(1 TSRMLS_CC, "O", &mysql_link, mysqli_link_class_entry)==FAILURE) {
    1108           1 :                                 return;
    1109             :                         }
    1110           8 :                         break;
    1111             :                 case 2:
    1112           5 :                         if (zend_parse_parameters(2 TSRMLS_CC, "Ol", &mysql_link, mysqli_link_class_entry, &resmode)==FAILURE) {
    1113           1 :                                 return;
    1114             :                         }
    1115           4 :                         break;
    1116             :                 default:
    1117           1 :                         WRONG_PARAM_COUNT;
    1118             :         }
    1119             : 
    1120          12 :         MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
    1121             : 
    1122           8 :         switch (resmode) {
    1123             :                 case MYSQLI_STORE_RESULT:
    1124           6 :                         result = mysql_store_result(mysql->mysql);
    1125           6 :                         break;
    1126             :                 case MYSQLI_USE_RESULT:
    1127           1 :                         result = mysql_use_result(mysql->mysql);
    1128           1 :                         break;
    1129             :                 default:
    1130           1 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid value for resultmode");
    1131             :         }
    1132             : 
    1133           8 :         if (!result) {
    1134           6 :                 RETURN_FALSE;
    1135             :         }
    1136             : 
    1137           2 :         mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
    1138           2 :         mysqli_resource->ptr = (void *)result;
    1139           2 :         mysqli_resource->status = MYSQLI_STATUS_VALID;
    1140             : 
    1141           2 :         ((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->ptr = mysqli_resource;
    1142             : 
    1143             : }
    1144             : /* }}} */
    1145             : 
    1146             : 
    1147             : /* {{{ php_mysqli_fetch_into_hash_aux
    1148             :  */
    1149       59965 : void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * result, long fetchtype TSRMLS_DC)
    1150             : {
    1151             : #if !defined(MYSQLI_USE_MYSQLND)
    1152             :         MYSQL_ROW row;
    1153             :         unsigned int    i;
    1154             :         MYSQL_FIELD             *fields;
    1155             :         unsigned long   *field_len;
    1156             :         
    1157             :         if (!(row = mysql_fetch_row(result))) {
    1158             :                 RETURN_NULL();
    1159             :         }
    1160             : 
    1161             :         if (fetchtype & MYSQLI_ASSOC) {
    1162             :                 fields = mysql_fetch_fields(result);
    1163             :         }
    1164             : 
    1165             :         array_init(return_value);
    1166             :         field_len = mysql_fetch_lengths(result);
    1167             : 
    1168             :         for (i = 0; i < mysql_num_fields(result); i++) {
    1169             :                 if (row[i]) {
    1170             :                         zval *res;
    1171             : 
    1172             :                         MAKE_STD_ZVAL(res);
    1173             : 
    1174             : #if MYSQL_VERSION_ID > 50002
    1175             :                         if (mysql_fetch_field_direct(result, i)->type == MYSQL_TYPE_BIT) {
    1176             :                                 my_ulonglong llval;
    1177             :                                 char tmp[22];
    1178             :                                 switch (field_len[i]) {
    1179             :                                         case 8:llval = (my_ulonglong)  bit_uint8korr(row[i]);break;
    1180             :                                         case 7:llval = (my_ulonglong)  bit_uint7korr(row[i]);break;
    1181             :                                         case 6:llval = (my_ulonglong)  bit_uint6korr(row[i]);break;
    1182             :                                         case 5:llval = (my_ulonglong)  bit_uint5korr(row[i]);break;
    1183             :                                         case 4:llval = (my_ulonglong)  bit_uint4korr(row[i]);break;
    1184             :                                         case 3:llval = (my_ulonglong)  bit_uint3korr(row[i]);break;
    1185             :                                         case 2:llval = (my_ulonglong)  bit_uint2korr(row[i]);break;
    1186             :                                         case 1:llval = (my_ulonglong)  uint1korr(row[i]);break;
    1187             :                                 }
    1188             :                                 /* even though lval is declared as unsigned, the value
    1189             :                                  * may be negative. Therefor we cannot use MYSQLI_LLU_SPEC and must
    1190             :                                  * use MYSQLI_LL_SPEC.
    1191             :                                  */
    1192             :                                 snprintf(tmp, sizeof(tmp), (mysql_fetch_field_direct(result, i)->flags & UNSIGNED_FLAG)? MYSQLI_LLU_SPEC : MYSQLI_LL_SPEC, llval);
    1193             :                                 ZVAL_STRING(res, tmp, 1);
    1194             :                         } else
    1195             : #endif
    1196             :                         {
    1197             : 
    1198             : #if PHP_API_VERSION < 20100412
    1199             :                                 /* check if we need magic quotes */
    1200             :                                 if (PG(magic_quotes_runtime)) {
    1201             :                                         Z_TYPE_P(res) = IS_STRING;
    1202             :                                         Z_STRVAL_P(res) = php_addslashes(row[i], field_len[i], &Z_STRLEN_P(res), 0 TSRMLS_CC);
    1203             :                                 } else {
    1204             : #endif
    1205             :                                         ZVAL_STRINGL(res, row[i], field_len[i], 1);
    1206             : #if PHP_API_VERSION < 20100412
    1207             :                                 }
    1208             : #endif
    1209             :                         }
    1210             : 
    1211             :                         if (fetchtype & MYSQLI_NUM) {
    1212             :                                 add_index_zval(return_value, i, res);
    1213             :                         }
    1214             :                         if (fetchtype & MYSQLI_ASSOC) {
    1215             :                                 if (fetchtype & MYSQLI_NUM) {
    1216             :                                         Z_ADDREF_P(res);
    1217             :                                 }
    1218             :                                 add_assoc_zval(return_value, fields[i].name, res);
    1219             :                         }
    1220             :                 } else {
    1221             :                         if (fetchtype & MYSQLI_NUM) {
    1222             :                                 add_index_null(return_value, i);
    1223             :                         }
    1224             :                         if (fetchtype & MYSQLI_ASSOC) {
    1225             :                                 add_assoc_null(return_value, fields[i].name);
    1226             :                         }
    1227             :                 }
    1228             :         }
    1229             : #else
    1230       59965 :         mysqlnd_fetch_into(result, ((fetchtype & MYSQLI_NUM)? MYSQLND_FETCH_NUM:0) | ((fetchtype & MYSQLI_ASSOC)? MYSQLND_FETCH_ASSOC:0), return_value, MYSQLND_MYSQLI);
    1231             : #endif
    1232       59965 : }
    1233             : /* }}} */
    1234             : 
    1235             : 
    1236             : /* {{{ php_mysqli_fetch_into_hash
    1237             :  */
    1238       59962 : void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags, int into_object)
    1239             : {
    1240             :         MYSQL_RES               *result;
    1241             :         zval                    *mysql_result;
    1242             :         long                    fetchtype;
    1243       59962 :         zval                    *ctor_params = NULL;
    1244       59962 :         zend_class_entry *ce = NULL;
    1245             : 
    1246       59962 :         if (into_object) {
    1247             :                 char *class_name;
    1248             :                 int class_name_len;
    1249             : 
    1250          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) {
    1251           5 :                         return;
    1252             :                 }
    1253          28 :                 if (ZEND_NUM_ARGS() < (getThis() ? 1 : 2)) {
    1254          12 :                         ce = zend_standard_class_def;
    1255             :                 } else {
    1256          16 :                         ce = zend_fetch_class(class_name, class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
    1257             :                 }
    1258          26 :                 if (!ce) {
    1259           0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not find class '%s'", class_name);
    1260           0 :                         return;
    1261             :                 }
    1262          26 :                 fetchtype = MYSQLI_ASSOC;
    1263             :         } else {
    1264       59929 :                 if (override_flags) {
    1265       18315 :                         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
    1266           6 :                                 return;
    1267             :                         }
    1268       18309 :                         fetchtype = override_flags;
    1269             :                 } else {
    1270       41614 :                         fetchtype = MYSQLI_BOTH;
    1271       41614 :                         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|l", &mysql_result, mysqli_result_class_entry, &fetchtype) == FAILURE) {
    1272           2 :                                 return;
    1273             :                         }
    1274             :                 }
    1275             :         }
    1276       59947 :         MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
    1277             : 
    1278       59934 :         if (fetchtype < MYSQLI_ASSOC || fetchtype > MYSQLI_BOTH) {
    1279           4 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "The result type should be either MYSQLI_NUM, MYSQLI_ASSOC or MYSQLI_BOTH");
    1280           4 :                 RETURN_FALSE;
    1281             :         }
    1282             : 
    1283       59930 :         php_mysqli_fetch_into_hash_aux(return_value, result, fetchtype TSRMLS_CC);
    1284             : 
    1285       59930 :         if (into_object && Z_TYPE_P(return_value) == IS_ARRAY) {
    1286          18 :                 zval dataset = *return_value;
    1287             :                 zend_fcall_info fci;
    1288             :                 zend_fcall_info_cache fcc;
    1289             :                 zval *retval_ptr;
    1290             : 
    1291          18 :                 object_and_properties_init(return_value, ce, NULL);
    1292          18 :                 zend_merge_properties(return_value, Z_ARRVAL(dataset), 1 TSRMLS_CC);
    1293             : 
    1294          18 :                 if (ce->constructor) {
    1295           9 :                         fci.size = sizeof(fci);
    1296           9 :                         fci.function_table = &ce->function_table;
    1297           9 :                         fci.function_name = NULL;
    1298           9 :                         fci.symbol_table = NULL;
    1299           9 :                         fci.object_ptr = return_value;
    1300           9 :                         fci.retval_ptr_ptr = &retval_ptr;
    1301           9 :                         fci.params = NULL;
    1302           9 :                         fci.param_count = 0;
    1303           9 :                         fci.no_separation = 1;
    1304             : 
    1305           9 :                         if (ctor_params && Z_TYPE_P(ctor_params) != IS_NULL) {
    1306           8 :                                 if (zend_fcall_info_args(&fci, ctor_params TSRMLS_CC) == FAILURE) {
    1307             :                                         /* Two problems why we throw exceptions here: PHP is typeless
    1308             :                                          * and hence passing one argument that's not an array could be
    1309             :                                          * by mistake and the other way round is possible, too. The
    1310             :                                          * single value is an array. Also we'd have to make that one
    1311             :                                          * argument passed by reference.
    1312             :                                          */
    1313           1 :                                         zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Parameter ctor_params must be an array", 0 TSRMLS_CC);
    1314           1 :                                         return;
    1315             :                                 }
    1316             :                         }
    1317             : 
    1318           8 :                         fcc.initialized = 1;
    1319           8 :                         fcc.function_handler = ce->constructor;
    1320           8 :                         fcc.calling_scope = EG(scope);
    1321           8 :                         fcc.called_scope = Z_OBJCE_P(return_value);
    1322           8 :                         fcc.object_ptr = return_value;
    1323             : 
    1324           8 :                         if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) {
    1325           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);
    1326             :                         } else {
    1327           8 :                                 if (retval_ptr) {
    1328           8 :                                         zval_ptr_dtor(&retval_ptr);
    1329             :                                 }
    1330             :                         }
    1331           8 :                         if (fci.params) {
    1332           7 :                                 efree(fci.params);
    1333             :                         }
    1334           9 :                 } else if (ctor_params) {
    1335           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);
    1336             :                 }
    1337             :         }
    1338             : }
    1339             : /* }}} */
    1340             : 
    1341             : /*
    1342             :  * Local variables:
    1343             :  * tab-width: 4
    1344             :  * c-basic-offset: 4
    1345             :  * End:
    1346             :  * vim600: noet sw=4 ts=4 fdm=marker
    1347             :  * vim<600: noet sw=4 ts=4
    1348             :  */

Generated by: LCOV version 1.10

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

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