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

Generated by: LCOV version 1.10

Generated at Wed, 27 Apr 2016 15:51:42 +0000 (29 hours ago)

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