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

Generated by: LCOV version 1.10

Generated at Tue, 14 Oct 2014 07:25:43 +0000 (7 days ago)

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