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: 509 557 91.4 %
Date: 2015-07-05 Functions: 28 31 90.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Sun, 05 Jul 2015 15:44:50 +0000 (2 days ago)

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