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

LCOV - code coverage report
Current view: top level - ext/mysqli - mysqli.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 509 557 91.4 %
Date: 2015-08-25 Functions: 28 31 90.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Tue, 25 Aug 2015 07:24:20 +0000 (3 days ago)

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