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

Generated by: LCOV version 1.10

Generated at Mon, 26 Jan 2015 14:46:47 +0000 (3 days ago)

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