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_nonapi.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 385 435 88.5 %
Date: 2014-11-25 Functions: 25 26 96.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | PHP Version 5                                                        |
       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 "php_mysqli_structs.h"
      33             : #include "mysqli_priv.h"
      34             : 
      35             : #define SAFE_STR(a) ((a)?a:"")
      36             : 
      37             : #ifndef zend_parse_parameters_none
      38             : #define zend_parse_parameters_none()    \
      39             :         zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "")
      40             : #endif
      41             : 
      42             : /* {{{ php_mysqli_set_error
      43             :  */
      44        1157 : static void php_mysqli_set_error(long mysql_errno, char *mysql_err TSRMLS_DC)
      45             : {
      46        1157 :         MyG(error_no) = mysql_errno;
      47        1157 :         if (MyG(error_msg)) {
      48          17 :                 efree(MyG(error_msg));
      49             :         }
      50        1182 :         if(mysql_err && *mysql_err) {
      51          25 :                 MyG(error_msg) = estrdup(mysql_err);
      52             :         } else {
      53        1132 :                 MyG(error_msg) = NULL;
      54             :         }
      55        1157 : }
      56             : /* }}} */
      57             : 
      58             : 
      59        1239 : void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_connect, zend_bool in_ctor)
      60             : {
      61        1239 :         MY_MYSQL                        *mysql = NULL;
      62        1239 :         MYSQLI_RESOURCE         *mysqli_resource = NULL;
      63        1239 :         zval                            *object = getThis();
      64        1239 :         char                            *hostname = NULL, *username=NULL, *passwd=NULL, *dbname=NULL, *socket=NULL;
      65        1239 :         int                                     hostname_len = 0, username_len = 0, passwd_len = 0, dbname_len = 0, socket_len = 0;
      66        1239 :         zend_bool                       persistent = FALSE;
      67        1239 :         long                            port = 0, flags = 0;
      68             :         uint                            hash_len;
      69        1239 :         char                            *hash_key = NULL;
      70        1239 :         zend_bool                       new_connection = FALSE;
      71             :         zend_rsrc_list_entry    *le;
      72        1239 :         mysqli_plist_entry *plist = NULL;
      73        1239 :         zend_bool                       self_alloced = 0;
      74             : 
      75             : 
      76             : #if !defined(MYSQL_USE_MYSQLND)
      77             :         if ((MYSQL_VERSION_ID / 100) != (mysql_get_client_version() / 100)) {
      78             :                 php_error_docref(NULL TSRMLS_CC, E_WARNING,
      79             :                                                 "Headers and client library minor version mismatch. Headers:%d Library:%ld",
      80             :                                                 MYSQL_VERSION_ID, mysql_get_client_version());
      81             :         }
      82             : #endif
      83             : 
      84        1239 :         if (getThis() && !ZEND_NUM_ARGS() && in_ctor) {
      85          16 :                 php_mysqli_init(INTERNAL_FUNCTION_PARAM_PASSTHRU);
      86          16 :                 return;
      87             :         }
      88        1223 :         hostname = username = dbname = passwd = socket = NULL;
      89             : 
      90        1223 :         if (!is_real_connect) {
      91          73 :                 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ssssls", &hostname, &hostname_len, &username, &username_len,
      92             :                                                                         &passwd, &passwd_len, &dbname, &dbname_len, &port, &socket, &socket_len) == FAILURE) {
      93           1 :                         return;
      94             :                 }
      95             : 
      96          72 :                 if (object && instanceof_function(Z_OBJCE_P(object), mysqli_link_class_entry TSRMLS_CC)) {
      97          41 :                         mysqli_resource = ((mysqli_object *) zend_object_store_get_object(object TSRMLS_CC))->ptr;
      98          41 :                         if (mysqli_resource && mysqli_resource->ptr) {
      99           7 :                                 mysql = (MY_MYSQL*) mysqli_resource->ptr;
     100             :                         }
     101             :                 }
     102          72 :                 if (!mysql) {
     103          65 :                         mysql = (MY_MYSQL *) ecalloc(1, sizeof(MY_MYSQL));
     104          65 :                         self_alloced = 1;
     105             :                 }
     106          72 :                 flags |= CLIENT_MULTI_RESULTS; /* needed for mysql_multi_query() */
     107             :         } else {
     108             :                 /* We have flags too */
     109        1150 :                 if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|sssslsl", &object, mysqli_link_class_entry,
     110             :                                                                                 &hostname, &hostname_len, &username, &username_len, &passwd, &passwd_len, &dbname, &dbname_len, &port, &socket, &socket_len,
     111             :                                                                                 &flags) == FAILURE) {
     112           8 :                         return;
     113             :                 }
     114             : 
     115        1142 :                 mysqli_resource = ((mysqli_object *) zend_object_store_get_object(object TSRMLS_CC))->ptr;
     116        1142 :                 MYSQLI_FETCH_RESOURCE_CONN(mysql, &object, MYSQLI_STATUS_INITIALIZED);
     117             : 
     118             :                 /* set some required options */
     119        1141 :                 flags |= CLIENT_MULTI_RESULTS; /* needed for mysql_multi_query() */
     120             :                 /* remove some insecure options */
     121        1141 :                 flags &= ~CLIENT_MULTI_STATEMENTS;   /* don't allow multi_queries via connect parameter */
     122        1141 :                 if (PG(open_basedir) && PG(open_basedir)[0] != '\0') {
     123           1 :                         flags &= ~CLIENT_LOCAL_FILES;
     124             :                 }
     125             :         }
     126             : 
     127        1213 :         if (!socket_len || !socket) {
     128          48 :                 socket = MyG(default_socket);
     129             :         }
     130        1213 :         if (!port){
     131          39 :                 port = MyG(default_port);
     132             :         }
     133        1213 :         if (!passwd) {
     134          26 :                 passwd = MyG(default_pw);
     135          26 :                 passwd_len = strlen(SAFE_STR(passwd));
     136             :         }
     137        1213 :         if (!username){
     138          19 :                 username = MyG(default_user);
     139             :         }
     140        1213 :         if (!hostname || !hostname_len) {
     141          17 :                 hostname = MyG(default_host);
     142             :         }
     143             : 
     144        2361 :         if (mysql->mysql && mysqli_resource &&
     145        1148 :                 (mysqli_resource->status > MYSQLI_STATUS_INITIALIZED))
     146             :         {
     147             :                 /* already connected, we should close the connection */
     148          13 :                 php_mysqli_close(mysql, MYSQLI_CLOSE_IMPLICIT, mysqli_resource->status TSRMLS_CC);
     149             :         }
     150             : 
     151        1213 :         if (strlen(SAFE_STR(hostname)) > 2 && !strncasecmp(hostname, "p:", 2)) {
     152          89 :                 hostname += 2;
     153          89 :                 if (!MyG(allow_persistent)) {
     154           0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Persistent connections are disabled. Downgrading to normal");
     155             :                 } else {
     156          89 :                         mysql->persistent = persistent = TRUE;
     157             : 
     158         267 :                         hash_len = spprintf(&hash_key, 0, "mysqli_%s_%s%ld%s%s%s", SAFE_STR(hostname), SAFE_STR(socket),
     159         178 :                                                                 port, SAFE_STR(username), SAFE_STR(dbname),
     160          89 :                                                                 SAFE_STR(passwd));
     161             : 
     162          89 :                         mysql->hash_key = hash_key;
     163             : 
     164             :                         /* check if we can reuse exisiting connection ... */
     165          89 :                         if (zend_hash_find(&EG(persistent_list), hash_key, hash_len + 1, (void **)&le) == SUCCESS) {
     166          75 :                                 if (Z_TYPE_P(le) == php_le_pmysqli()) {
     167          75 :                                         plist = (mysqli_plist_entry *) le->ptr;
     168             : 
     169             :                                         do {
     170          75 :                                                 if (zend_ptr_stack_num_elements(&plist->free_links)) {
     171         100 :                                                         mysql->mysql = zend_ptr_stack_pop(&plist->free_links);
     172             : 
     173          50 :                                                         MyG(num_inactive_persistent)--;
     174             :                                                         /* reset variables */
     175             : 
     176             : #ifndef MYSQLI_NO_CHANGE_USER_ON_PCONNECT
     177          50 :                                                         if (!mysqli_change_user_silent(mysql->mysql, username, passwd, dbname, passwd_len)) {
     178             : #else
     179             :                                                         if (!mysql_ping(mysql->mysql)) {
     180             : #endif
     181             : #ifdef MYSQLI_USE_MYSQLND
     182          49 :                                                                 mysqlnd_restart_psession(mysql->mysql);
     183             : #endif
     184          49 :                                                                 MyG(num_active_persistent)++;
     185          49 :                                                                 goto end;
     186             :                                                         } else {
     187           1 :                                                                 mysqli_close(mysql->mysql, MYSQLI_CLOSE_IMPLICIT);
     188           1 :                                                                 mysql->mysql = NULL;
     189             :                                                         }
     190             :                                                 }
     191             :                                         } while (0);
     192             :                                 }
     193             :                         } else {
     194             :                                 zend_rsrc_list_entry le;
     195          14 :                                 le.type = php_le_pmysqli();
     196          14 :                                 le.ptr = plist = calloc(1, sizeof(mysqli_plist_entry));
     197             : 
     198          14 :                                 zend_ptr_stack_init_ex(&plist->free_links, 1);
     199          14 :                                 zend_hash_update(&EG(persistent_list), hash_key, hash_len + 1, (void *)&le, sizeof(le), NULL);
     200             :                         }
     201             :                 }
     202             :         }
     203        1164 :         if (MyG(max_links) != -1 && MyG(num_links) >= MyG(max_links)) {
     204           5 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too many open links (%ld)", MyG(num_links));
     205           5 :                 goto err;
     206             :         }
     207             : 
     208        1169 :         if (persistent && MyG(max_persistent) != -1 &&
     209          10 :                 (MyG(num_active_persistent) + MyG(num_inactive_persistent))>= MyG(max_persistent))
     210             :         {
     211           2 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too many open persistent links (%ld)",
     212           2 :                                                                 MyG(num_active_persistent) + MyG(num_inactive_persistent));
     213           2 :                 goto err;
     214             :         }
     215        1157 :         if (!mysql->mysql) {
     216             : #if !defined(MYSQLI_USE_MYSQLND)
     217             :                 if (!(mysql->mysql = mysql_init(NULL))) {
     218             : #else
     219          71 :                 if (!(mysql->mysql = mysqlnd_init(persistent))) {
     220             : #endif
     221           0 :                         goto err;
     222             :                 }
     223          71 :                 new_connection = TRUE;
     224             :         }
     225             : 
     226             : #ifdef HAVE_EMBEDDED_MYSQLI
     227             :         if (hostname_len) {
     228             :                 unsigned int external=1;
     229             :                 mysql_options(mysql->mysql, MYSQL_OPT_USE_REMOTE_CONNECTION, (char *)&external);
     230             :         } else {
     231             :                 mysql_options(mysql->mysql, MYSQL_OPT_USE_EMBEDDED_CONNECTION, 0);
     232             :         }
     233             : #endif
     234             : 
     235             : #if !defined(MYSQLI_USE_MYSQLND)
     236             :         /* BC for prior to bug fix #53425 */
     237             :         flags |= CLIENT_MULTI_RESULTS;
     238             : 
     239             :         if (mysql_real_connect(mysql->mysql, hostname, username, passwd, dbname, port, socket, flags) == NULL)
     240             : #else
     241        1157 :         if (mysqlnd_connect(mysql->mysql, hostname, username, passwd, passwd_len, dbname, dbname_len,
     242             :                                                 port, socket, flags TSRMLS_CC) == NULL)
     243             : #endif
     244             :         {
     245             :                 /* Save error messages - for mysqli_connect_error() & mysqli_connect_errno() */
     246          28 :                 php_mysqli_set_error(mysql_errno(mysql->mysql), (char *) mysql_error(mysql->mysql) TSRMLS_CC);
     247          56 :                 php_mysqli_throw_sql_exception((char *)mysql_sqlstate(mysql->mysql), mysql_errno(mysql->mysql) TSRMLS_CC,
     248          56 :                                                                                 "%s", mysql_error(mysql->mysql));
     249          28 :                 if (!is_real_connect) {
     250             :                         /* free mysql structure */
     251          13 :                         mysqli_close(mysql->mysql, MYSQLI_CLOSE_DISCONNECTED);
     252          13 :                         mysql->mysql = NULL;
     253             :                 }
     254          28 :                 goto err;
     255             :         }
     256             : 
     257             :         /* clear error */
     258        1129 :         php_mysqli_set_error(mysql_errno(mysql->mysql), (char *) mysql_error(mysql->mysql) TSRMLS_CC);
     259             : 
     260             : #if !defined(MYSQLI_USE_MYSQLND)
     261             :         mysql->mysql->reconnect = MyG(reconnect);
     262             : 
     263             :         /* set our own local_infile handler */
     264             :         php_set_local_infile_handler_default(mysql);
     265             : #endif
     266             : 
     267        1129 :         mysql_options(mysql->mysql, MYSQL_OPT_LOCAL_INFILE, (char *)&MyG(allow_local_infile));
     268             : 
     269             : end:
     270        1178 :         if (!mysqli_resource) {
     271          52 :                 mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
     272          52 :                 mysqli_resource->ptr = (void *)mysql;
     273             :         }
     274        1178 :         mysqli_resource->status = MYSQLI_STATUS_VALID;
     275             : 
     276             :         /* store persistent connection */
     277        1178 :         if (persistent && (new_connection || is_real_connect)) {
     278          81 :                 MyG(num_active_persistent)++;
     279             :         }
     280             : 
     281        1178 :         MyG(num_links)++;
     282             : 
     283        1178 :         mysql->multi_query = 0;
     284             : 
     285        1200 :         if (!object || !instanceof_function(Z_OBJCE_P(object), mysqli_link_class_entry TSRMLS_CC)) {
     286          22 :                 MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_link_class_entry);
     287             :         } else {
     288        1156 :                 ((mysqli_object *) zend_object_store_get_object(object TSRMLS_CC))->ptr = mysqli_resource;
     289             :         }
     290        1178 :         if (!is_real_connect) {
     291          59 :                 return;
     292             :         } else {
     293        1119 :                 RETURN_TRUE;
     294             :         }
     295             : 
     296             : err:
     297          35 :         if (mysql->hash_key) {
     298           4 :                 efree(mysql->hash_key);
     299           4 :                 mysql->hash_key = NULL;
     300           4 :                 mysql->persistent = FALSE;
     301             :         }
     302          35 :         if (!is_real_connect && self_alloced) {
     303          13 :                 efree(mysql);
     304             :         }
     305          35 :         RETVAL_FALSE;
     306             : }
     307             : 
     308             : 
     309             : /* {{{ proto object mysqli_connect([string hostname [,string username [,string passwd [,string dbname [,int port [,string socket]]]]]])
     310             :    Open a connection to a mysql server */
     311          45 : PHP_FUNCTION(mysqli_connect)
     312             : {
     313          45 :         mysqli_common_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, FALSE, FALSE);
     314          45 : }
     315             : /* }}} */
     316             : 
     317             : 
     318             : /* {{{ proto object mysqli_link_construct()
     319             :   */
     320          44 : PHP_FUNCTION(mysqli_link_construct)
     321             : {
     322          44 :         mysqli_common_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, FALSE, TRUE);
     323          44 : }
     324             : /* }}} */
     325             : 
     326             : 
     327             : /* {{{ proto int mysqli_connect_errno(void)
     328             :    Returns the numerical value of the error message from last connect command */
     329          24 : PHP_FUNCTION(mysqli_connect_errno)
     330             : {
     331          24 :         RETURN_LONG(MyG(error_no));
     332             : }
     333             : /* }}} */
     334             : 
     335             : /* {{{ proto string mysqli_connect_error(void)
     336             :    Returns the text of the error message from previous MySQL operation */
     337          17 : PHP_FUNCTION(mysqli_connect_error)
     338             : {
     339          17 :         if (MyG(error_msg)) {
     340           7 :                 RETURN_STRING(MyG(error_msg),1);
     341             :         } else {
     342          10 :                 RETURN_NULL();
     343             :         }
     344             : }
     345             : /* }}} */
     346             : 
     347             : 
     348             : /* {{{ proto mixed mysqli_fetch_array (object result [,int resulttype])
     349             :    Fetch a result row as an associative array, a numeric array, or both */
     350       40335 : PHP_FUNCTION(mysqli_fetch_array)
     351             : {
     352       40335 :         php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 0);
     353       40335 : }
     354             : /* }}} */
     355             : 
     356             : /* {{{ proto mixed mysqli_fetch_assoc (object result)
     357             :    Fetch a result row as an associative array */
     358       18293 : PHP_FUNCTION(mysqli_fetch_assoc)
     359             : {
     360       18293 :         php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, MYSQLI_ASSOC, 0);
     361       18293 : }
     362             : /* }}} */
     363             : 
     364             : 
     365             : /* {{{ proto mixed mysqli_fetch_all (object result [,int resulttype])
     366             :    Fetches all result rows as an associative array, a numeric array, or both */
     367             : #if defined(MYSQLI_USE_MYSQLND)
     368         209 : PHP_FUNCTION(mysqli_fetch_all)
     369             : {
     370             :         MYSQL_RES       *result;
     371             :         zval            *mysql_result;
     372         209 :         long            mode = MYSQLND_FETCH_NUM;
     373             : 
     374         209 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|l", &mysql_result, mysqli_result_class_entry, &mode) == FAILURE) {
     375           2 :                 return;
     376             :         }
     377         207 :         MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
     378             : 
     379         207 :         if (!mode || (mode & ~MYSQLND_FETCH_BOTH)) {
     380           2 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Mode can be only MYSQLI_FETCH_NUM, "
     381             :                                  "MYSQLI_FETCH_ASSOC or MYSQLI_FETCH_BOTH");
     382           2 :                 RETURN_FALSE;
     383             :         }
     384             : 
     385         205 :         mysqlnd_fetch_all(result, mode, return_value);
     386             : }
     387             : /* }}} */
     388             : 
     389             : 
     390             : 
     391             : /* {{{ proto array mysqli_get_client_stats(void)
     392             :    Returns statistics about the zval cache */
     393          50 : PHP_FUNCTION(mysqli_get_client_stats)
     394             : {
     395          50 :         if (zend_parse_parameters_none() == FAILURE) {
     396           1 :                 return;
     397             :         }
     398          49 :         mysqlnd_get_client_stats(return_value);
     399             : }
     400             : /* }}} */
     401             : 
     402             : 
     403             : /* {{{ proto array mysqli_get_connection_stats(void)
     404             :    Returns statistics about the zval cache */
     405           7 : PHP_FUNCTION(mysqli_get_connection_stats)
     406             : {
     407             :         MY_MYSQL        *mysql;
     408             :         zval            *mysql_link;
     409             : 
     410           7 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
     411             :                                                                          &mysql_link, mysqli_link_class_entry) == FAILURE) {
     412           2 :                 return;
     413             :         }
     414           5 :         MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
     415             : 
     416           5 :         mysqlnd_get_connection_stats(mysql->mysql, return_value);
     417             : }
     418             : #endif
     419             : /* }}} */
     420             : 
     421             : /* {{{ proto mixed mysqli_error_list (object connection)
     422             :    Fetches all client errors */
     423           1 : PHP_FUNCTION(mysqli_error_list)
     424             : {
     425             :         MY_MYSQL        *mysql;
     426             :         zval            *mysql_link;
     427             : 
     428           1 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
     429           0 :                 return;
     430             :         }
     431           1 :         MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
     432           1 :         array_init(return_value);
     433             : #if defined(MYSQLI_USE_MYSQLND)
     434           1 :         if (mysql->mysql->data->error_info->error_list) {
     435             :                 MYSQLND_ERROR_LIST_ELEMENT * message;
     436             :                 zend_llist_position pos;
     437           2 :                 for (message = (MYSQLND_ERROR_LIST_ELEMENT *) zend_llist_get_first_ex(mysql->mysql->data->error_info->error_list, &pos);
     438             :                          message;
     439           0 :                          message = (MYSQLND_ERROR_LIST_ELEMENT *) zend_llist_get_next_ex(mysql->mysql->data->error_info->error_list, &pos)) 
     440             :                 {
     441             :                         zval * single_error;
     442           0 :                         MAKE_STD_ZVAL(single_error);
     443           0 :                         array_init(single_error);
     444           0 :                         add_assoc_long_ex(single_error, "errno", sizeof("errno"), message->error_no);
     445           0 :                         add_assoc_string_ex(single_error, "sqlstate", sizeof("sqlstate"), message->sqlstate, 1);
     446           0 :                         add_assoc_string_ex(single_error, "error", sizeof("error"), message->error, 1);
     447           0 :                         add_next_index_zval(return_value, single_error);
     448             :                 }
     449             :         }
     450             : #else
     451             :         if (mysql_errno(mysql->mysql)) {
     452             :                 zval * single_error;
     453             :                 MAKE_STD_ZVAL(single_error);
     454             :                 array_init(single_error);
     455             :                 add_assoc_long_ex(single_error, "errno", sizeof("errno"), mysql_errno(mysql->mysql));
     456             :                 add_assoc_string_ex(single_error, "sqlstate", sizeof("sqlstate"), mysql_sqlstate(mysql->mysql), 1);
     457             :                 add_assoc_string_ex(single_error, "error", sizeof("error"), mysql_error(mysql->mysql), 1);
     458             :                 add_next_index_zval(return_value, single_error);
     459             :         }
     460             : #endif
     461             : }
     462             : /* }}} */
     463             : 
     464             : 
     465             : /* {{{ proto string mysqli_stmt_error_list(object stmt)
     466             : */
     467           1 : PHP_FUNCTION(mysqli_stmt_error_list)
     468             : {
     469             :         MY_STMT *stmt;
     470             :         zval    *mysql_stmt;
     471             : 
     472           1 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
     473           0 :                 return;
     474             :         }
     475           1 :         MYSQLI_FETCH_RESOURCE_STMT(stmt, &mysql_stmt, MYSQLI_STATUS_INITIALIZED);
     476           1 :         array_init(return_value);
     477             : #if defined(MYSQLI_USE_MYSQLND)
     478           1 :         if (stmt->stmt && stmt->stmt->data && stmt->stmt->data->error_info->error_list) {
     479             :                 MYSQLND_ERROR_LIST_ELEMENT * message;
     480             :                 zend_llist_position pos;
     481           2 :                 for (message = (MYSQLND_ERROR_LIST_ELEMENT *) zend_llist_get_first_ex(stmt->stmt->data->error_info->error_list, &pos);
     482             :                          message;
     483           0 :                          message = (MYSQLND_ERROR_LIST_ELEMENT *) zend_llist_get_next_ex(stmt->stmt->data->error_info->error_list, &pos)) 
     484             :                 {
     485             :                         zval * single_error;
     486           0 :                         MAKE_STD_ZVAL(single_error);
     487           0 :                         array_init(single_error);
     488           0 :                         add_assoc_long_ex(single_error, "errno", sizeof("errno"), message->error_no);
     489           0 :                         add_assoc_string_ex(single_error, "sqlstate", sizeof("sqlstate"), message->sqlstate, 1);
     490           0 :                         add_assoc_string_ex(single_error, "error", sizeof("error"), message->error, 1);
     491           0 :                         add_next_index_zval(return_value, single_error);
     492             :                 }
     493             :         }
     494             : #else
     495             :         if (mysql_stmt_errno(stmt->stmt)) {
     496             :                 zval * single_error;
     497             :                 MAKE_STD_ZVAL(single_error);
     498             :                 array_init(single_error);
     499             :                 add_assoc_long_ex(single_error, "errno", sizeof("errno"), mysql_stmt_errno(stmt->stmt));
     500             :                 add_assoc_string_ex(single_error, "sqlstate", sizeof("sqlstate"), mysql_stmt_sqlstate(stmt->stmt), 1);
     501             :                 add_assoc_string_ex(single_error, "error", sizeof("error"), mysql_stmt_error(stmt->stmt), 1);
     502             :                 add_next_index_zval(return_value, single_error);
     503             :         }
     504             : #endif
     505             : }
     506             : /* }}} */
     507             : 
     508             : 
     509             : /* {{{ proto mixed mysqli_fetch_object (object result [, string class_name [, NULL|array ctor_params]])
     510             :    Fetch a result row as an object */
     511          33 : PHP_FUNCTION(mysqli_fetch_object)
     512             : {
     513          33 :         php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, MYSQLI_ASSOC, 1);
     514          31 : }
     515             : /* }}} */
     516             : 
     517             : /* {{{ proto bool mysqli_multi_query(object link, string query)
     518             :    allows to execute multiple queries  */
     519          27 : PHP_FUNCTION(mysqli_multi_query)
     520             : {
     521             :         MY_MYSQL        *mysql;
     522             :         zval            *mysql_link;
     523          27 :         char            *query = NULL;
     524             :         int             query_len;
     525             : 
     526          27 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, &query, &query_len) == FAILURE) {
     527           2 :                 return;
     528             :         }
     529          25 :         MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
     530             : 
     531          24 :         MYSQLI_ENABLE_MQ;
     532          24 :         if (mysql_real_query(mysql->mysql, query, query_len)) {
     533             : #ifndef MYSQLI_USE_MYSQLND
     534             :                 char s_error[MYSQL_ERRMSG_SIZE], s_sqlstate[SQLSTATE_LENGTH+1];
     535             :                 unsigned int s_errno;
     536             :                 /* we have to save error information, cause
     537             :                 MYSQLI_DISABLE_MQ will reset error information */
     538             :                 strcpy(s_error, mysql_error(mysql->mysql));
     539             :                 strcpy(s_sqlstate, mysql_sqlstate(mysql->mysql));
     540             :                 s_errno = mysql_errno(mysql->mysql);
     541             : #else
     542           6 :                 MYSQLND_ERROR_INFO error_info = *mysql->mysql->data->error_info;
     543             : #endif
     544           6 :                 MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
     545           6 :                 MYSQLI_DISABLE_MQ;
     546             : 
     547             : #ifndef MYSQLI_USE_MYSQLND
     548             :                 /* restore error information */
     549             :                 strcpy(mysql->mysql->net.last_error, s_error);
     550             :                 strcpy(mysql->mysql->net.sqlstate, s_sqlstate);
     551             :                 mysql->mysql->net.last_errno = s_errno;
     552             : #else
     553           6 :                 *mysql->mysql->data->error_info = error_info;
     554             : #endif
     555           6 :                 RETURN_FALSE;
     556             :         }
     557          18 :         RETURN_TRUE;
     558             : }
     559             : /* }}} */
     560             : 
     561             : /* {{{ proto mixed mysqli_query(object link, string query [,int resultmode]) */
     562       17339 : PHP_FUNCTION(mysqli_query)
     563             : {
     564             :         MY_MYSQL                        *mysql;
     565             :         zval                            *mysql_link;
     566             :         MYSQLI_RESOURCE         *mysqli_resource;
     567       17339 :         MYSQL_RES                       *result = NULL;
     568       17339 :         char                            *query = NULL;
     569             :         int                             query_len;
     570       17339 :         long                            resultmode = MYSQLI_STORE_RESULT;
     571             : 
     572       17339 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|l", &mysql_link, mysqli_link_class_entry, &query, &query_len, &resultmode) == FAILURE) {
     573          14 :                 return;
     574             :         }
     575             : 
     576       17325 :         if (!query_len) {
     577           1 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty query");
     578           1 :                 RETURN_FALSE;
     579             :         }
     580       17324 :         if ((resultmode & ~MYSQLI_ASYNC) != MYSQLI_USE_RESULT && (resultmode & ~MYSQLI_ASYNC) != MYSQLI_STORE_RESULT) {
     581           1 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid value for resultmode");
     582           1 :                 RETURN_FALSE;
     583             :         }
     584             : 
     585       17323 :         MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
     586             : 
     587       17314 :         MYSQLI_DISABLE_MQ;
     588             : 
     589             : 
     590             : #ifdef MYSQLI_USE_MYSQLND
     591       17314 :         if (resultmode & MYSQLI_ASYNC) {
     592          27 :                 if (mysqli_async_query(mysql->mysql, query, query_len)) {
     593           2 :                         MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
     594           2 :                         RETURN_FALSE;
     595             :                 }
     596          25 :                 mysql->async_result_fetch_type = resultmode & ~MYSQLI_ASYNC;
     597          25 :                 RETURN_TRUE;
     598             :         }
     599             : #endif
     600             : 
     601       17287 :         if (mysql_real_query(mysql->mysql, query, query_len)) {
     602          63 :                 MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
     603          63 :                 RETURN_FALSE;
     604             :         }
     605             : 
     606       17224 :         if (!mysql_field_count(mysql->mysql)) {
     607             :                 /* no result set - not a SELECT */
     608       15693 :                 if (MyG(report_mode) & MYSQLI_REPORT_INDEX) {
     609           0 :                         php_mysqli_report_index(query, mysqli_server_status(mysql->mysql) TSRMLS_CC);
     610             :                 }
     611       15693 :                 RETURN_TRUE;
     612             :         }
     613             : 
     614        1531 :         switch (resultmode) {
     615             :                 case MYSQLI_STORE_RESULT:
     616        1518 :                         result = mysql_store_result(mysql->mysql);
     617        1518 :                         break;
     618             :                 case MYSQLI_USE_RESULT:
     619          13 :                         result = mysql_use_result(mysql->mysql);
     620             :                         break;
     621             :         }
     622        1531 :         if (!result) {
     623           0 :                 php_mysqli_throw_sql_exception((char *)mysql_sqlstate(mysql->mysql), mysql_errno(mysql->mysql) TSRMLS_CC,
     624           0 :                                                                                 "%s", mysql_error(mysql->mysql));
     625           0 :                 RETURN_FALSE;
     626             :         }
     627             : 
     628        1531 :         if (MyG(report_mode) & MYSQLI_REPORT_INDEX) {
     629           2 :                 php_mysqli_report_index(query, mysqli_server_status(mysql->mysql) TSRMLS_CC);
     630             :         }
     631             : 
     632        1531 :         mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
     633        1531 :         mysqli_resource->ptr = (void *)result;
     634        1531 :         mysqli_resource->status = MYSQLI_STATUS_VALID;
     635        1531 :         MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_result_class_entry);
     636             : }
     637             : /* }}} */
     638             : 
     639             : 
     640             : #if defined(MYSQLI_USE_MYSQLND)
     641             : #include "php_network.h"
     642             : /* {{{ mysqlnd_zval_array_to_mysqlnd_array functions */
     643          61 : static int mysqlnd_zval_array_to_mysqlnd_array(zval *in_array, MYSQLND ***out_array TSRMLS_DC)
     644             : {
     645             :         zval **elem;
     646          61 :         int i = 0, current = 0;
     647             : 
     648          61 :         if (Z_TYPE_P(in_array) != IS_ARRAY) {
     649           0 :                 return 0;
     650             :         }
     651          61 :         *out_array = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(in_array)) + 1, sizeof(MYSQLND *));
     652         241 :         for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(in_array));
     653         180 :                  zend_hash_get_current_data(Z_ARRVAL_P(in_array), (void **) &elem) == SUCCESS;
     654         119 :                  zend_hash_move_forward(Z_ARRVAL_P(in_array))) {
     655         119 :                 i++;
     656         238 :                 if (Z_TYPE_PP(elem) != IS_OBJECT ||
     657         119 :                         !instanceof_function(Z_OBJCE_PP(elem), mysqli_link_class_entry TSRMLS_CC)) {
     658           0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Parameter %d not a mysqli object", i);
     659             :                 } else {
     660             :                         MY_MYSQL *mysql;
     661             :                         MYSQLI_RESOURCE *my_res;
     662         119 :                         mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*elem TSRMLS_CC);
     663         119 :                         if (!(my_res = (MYSQLI_RESOURCE *)intern->ptr)) {
     664           2 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "[%d] Couldn't fetch %s", i, intern->zo.ce->name);
     665           2 :                                 continue;
     666             :                         }
     667         117 :                         mysql = (MY_MYSQL*) my_res->ptr;
     668         117 :                         if (MYSQLI_STATUS_VALID && my_res->status < MYSQLI_STATUS_VALID) {
     669           0 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid object %d or resource %s", i, intern->zo.ce->name);
     670           0 :                                 continue;
     671             :                         }
     672         117 :                         (*out_array)[current++] = mysql->mysql;
     673             :                 }
     674             :         }
     675          61 :         return 0;
     676             : }
     677             : /* }}} */
     678             : 
     679             : 
     680             : /* {{{ mysqlnd_zval_array_from_mysqlnd_array */
     681          61 : static int mysqlnd_zval_array_from_mysqlnd_array(MYSQLND **in_array, zval *out_array TSRMLS_DC)
     682             : {
     683          61 :         MYSQLND **p = in_array;
     684             :         HashTable *new_hash;
     685             :         zval **elem, **dest_elem;
     686          61 :         int ret = 0, i = 0;
     687             : 
     688          61 :         ALLOC_HASHTABLE(new_hash);
     689          61 :         zend_hash_init(new_hash, zend_hash_num_elements(Z_ARRVAL_P(out_array)), NULL, ZVAL_PTR_DTOR, 0);
     690             : 
     691         241 :         for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(out_array));
     692         180 :                  zend_hash_get_current_data(Z_ARRVAL_P(out_array), (void **) &elem) == SUCCESS;
     693         119 :                  zend_hash_move_forward(Z_ARRVAL_P(out_array)))
     694             :         {
     695         119 :                 i++;
     696         119 :                 if (Z_TYPE_PP(elem) != IS_OBJECT || !instanceof_function(Z_OBJCE_PP(elem), mysqli_link_class_entry TSRMLS_CC)) {
     697           0 :                         continue;
     698             :                 }
     699             :                 {
     700             :                         MY_MYSQL *mysql;
     701             :                         MYSQLI_RESOURCE *my_res;
     702         119 :                         mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*elem TSRMLS_CC);
     703         119 :                         if (!(my_res = (MYSQLI_RESOURCE *)intern->ptr)) {
     704           2 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "[%d] Couldn't fetch %s", i, intern->zo.ce->name);
     705           2 :                                 continue;
     706             :                         }
     707         117 :                         mysql = (MY_MYSQL *) my_res->ptr;
     708         117 :                         if (mysql->mysql == *p) {
     709          25 :                                 zend_hash_next_index_insert(new_hash, (void *)elem, sizeof(zval *), (void **)&dest_elem);
     710          25 :                                 if (dest_elem) {
     711          25 :                                         zval_add_ref(dest_elem);
     712             :                                 }
     713          25 :                                 ret++;
     714          25 :                                 p++;
     715             :                         }
     716             :                 }
     717             :         }
     718             : 
     719             :         /* destroy old array and add new one */
     720          61 :         zend_hash_destroy(Z_ARRVAL_P(out_array));
     721          61 :         efree(Z_ARRVAL_P(out_array));
     722             : 
     723          61 :         zend_hash_internal_pointer_reset(new_hash);
     724          61 :         Z_ARRVAL_P(out_array) = new_hash;
     725             : 
     726          61 :         return 0;
     727             : }
     728             : /* }}} */
     729             : 
     730             : 
     731             : /* {{{ mysqlnd_dont_poll_zval_array_from_mysqlnd_array */
     732          31 : static int mysqlnd_dont_poll_zval_array_from_mysqlnd_array(MYSQLND **in_array, zval *in_zval_array, zval *out_array TSRMLS_DC)
     733             : {
     734          31 :         MYSQLND **p = in_array;
     735             :         HashTable *new_hash;
     736             :         zval **elem, **dest_elem;
     737          31 :         int ret = 0;
     738             : 
     739          31 :         ALLOC_HASHTABLE(new_hash);
     740          31 :         zend_hash_init(new_hash, zend_hash_num_elements(Z_ARRVAL_P(in_zval_array)), NULL, ZVAL_PTR_DTOR, 0);
     741          31 :         if (in_array) {
     742          65 :                 for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(in_zval_array));
     743          47 :                          zend_hash_get_current_data(Z_ARRVAL_P(in_zval_array), (void **) &elem) == SUCCESS;
     744          29 :                          zend_hash_move_forward(Z_ARRVAL_P(in_zval_array)))
     745             :                 {
     746             :                         MY_MYSQL *mysql;
     747          29 :                         mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*elem TSRMLS_CC);
     748          29 :                         mysql = (MY_MYSQL *) ((MYSQLI_RESOURCE *)intern->ptr)->ptr;
     749          29 :                         if (mysql->mysql == *p) {
     750          20 :                                 zend_hash_next_index_insert(new_hash, (void *)elem, sizeof(zval *), (void **)&dest_elem);
     751          20 :                                 if (dest_elem) {
     752          20 :                                         zval_add_ref(dest_elem);
     753             :                                 }
     754          20 :                                 ret++;
     755          20 :                                 p++;
     756             :                         }
     757             :                 }
     758             :         }
     759             : 
     760             :         /* destroy old array and add new one */
     761          31 :         zend_hash_destroy(Z_ARRVAL_P(out_array));
     762          31 :         efree(Z_ARRVAL_P(out_array));
     763             : 
     764          31 :         zend_hash_internal_pointer_reset(new_hash);
     765          31 :         Z_ARRVAL_P(out_array) = new_hash;
     766             : 
     767          31 :         return 0;
     768             : }
     769             : /* }}} */
     770             : 
     771             : 
     772             : /* {{{ proto int mysqli_poll(array read, array write, array error, long sec [, long usec]) U
     773             :    Poll connections */
     774          38 : PHP_FUNCTION(mysqli_poll)
     775             : {
     776             :         zval                    *r_array, *e_array, *dont_poll_array;
     777          38 :         MYSQLND                 **new_r_array = NULL, **new_e_array = NULL, **new_dont_poll_array = NULL;
     778          38 :         long                    sec = 0, usec = 0;
     779             :         enum_func_status ret;
     780             :         int                     desc_num;
     781             : 
     782          38 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!a!al|l", &r_array, &e_array, &dont_poll_array, &sec, &usec) == FAILURE) {
     783           6 :                 return;
     784             :         }
     785          32 :         if (sec < 0 || usec < 0) {
     786           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Negative values passed for sec and/or usec");
     787           0 :                 RETURN_FALSE;
     788             :         }
     789             : 
     790          32 :         if (!r_array && !e_array) {
     791           1 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "No stream arrays were passed");
     792           1 :                 RETURN_FALSE;
     793             :         }
     794             : 
     795          31 :         if (r_array != NULL) {
     796          31 :                 mysqlnd_zval_array_to_mysqlnd_array(r_array, &new_r_array TSRMLS_CC);
     797             :         }
     798          31 :         if (e_array != NULL) {
     799          30 :                 mysqlnd_zval_array_to_mysqlnd_array(e_array, &new_e_array TSRMLS_CC);
     800             :         }
     801             : 
     802          31 :         ret = mysqlnd_poll(new_r_array, new_e_array, &new_dont_poll_array, sec, usec, &desc_num);
     803             : 
     804          31 :         mysqlnd_dont_poll_zval_array_from_mysqlnd_array(r_array != NULL ? new_dont_poll_array:NULL, r_array, dont_poll_array TSRMLS_CC);
     805             : 
     806          31 :         if (r_array != NULL) {
     807          31 :                 mysqlnd_zval_array_from_mysqlnd_array(new_r_array, r_array TSRMLS_CC);
     808             :         }
     809          31 :         if (e_array != NULL) {
     810          30 :                 mysqlnd_zval_array_from_mysqlnd_array(new_e_array, e_array TSRMLS_CC);
     811             :         }
     812             : 
     813          31 :         if (new_dont_poll_array) {
     814          18 :                 efree(new_dont_poll_array);
     815             :         }
     816          31 :         if (new_r_array) {
     817          31 :                 efree(new_r_array);
     818             :         }
     819          31 :         if (new_e_array) {
     820          30 :                 efree(new_e_array);
     821             :         }
     822          31 :         if (ret == PASS) {
     823          28 :                 RETURN_LONG(desc_num);
     824             :         } else {
     825           3 :                 RETURN_FALSE;
     826             :         }
     827             : }
     828             : /* }}} */
     829             : 
     830             : 
     831             : /* {{{ proto int mysqli_reap_async_query(object link) U
     832             :    Poll connections */
     833          24 : PHP_FUNCTION(mysqli_reap_async_query)
     834             : {
     835             :         MY_MYSQL                *mysql;
     836             :         zval                    *mysql_link;
     837             :         MYSQLI_RESOURCE         *mysqli_resource;
     838          24 :         MYSQL_RES                       *result = NULL;
     839             : 
     840          24 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
     841           0 :                 return;
     842             :         }
     843             : 
     844          24 :         MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
     845             : 
     846          24 :         if (FAIL == mysqlnd_reap_async_query(mysql->mysql)) {
     847           4 :                 RETURN_FALSE;
     848             :         }
     849             : 
     850          20 :         if (!mysql_field_count(mysql->mysql)) {
     851             :                 /* no result set - not a SELECT */
     852           7 :                 if (MyG(report_mode) & MYSQLI_REPORT_INDEX) {
     853             : /*                      php_mysqli_report_index("n/a", mysqli_server_status(mysql->mysql) TSRMLS_CC); */
     854             :                 }
     855           7 :                 RETURN_TRUE;
     856             :         }
     857             : 
     858          13 :         switch (mysql->async_result_fetch_type) {
     859             :                 case MYSQLI_STORE_RESULT:
     860           0 :                         result = mysql_store_result(mysql->mysql);
     861           0 :                         break;
     862             :                 case MYSQLI_USE_RESULT:
     863          13 :                         result = mysql_use_result(mysql->mysql);
     864             :                         break;
     865             :         }
     866             : 
     867          13 :         if (!result) {
     868           0 :                 php_mysqli_throw_sql_exception((char *)mysql_sqlstate(mysql->mysql), mysql_errno(mysql->mysql) TSRMLS_CC,
     869           0 :                                                                                 "%s", mysql_error(mysql->mysql));
     870           0 :                 RETURN_FALSE;
     871             :         }
     872             : 
     873          13 :         if (MyG(report_mode) & MYSQLI_REPORT_INDEX) {
     874             : /*              php_mysqli_report_index("n/a", mysqli_server_status(mysql->mysql) TSRMLS_CC); */
     875             :         }
     876             : 
     877          13 :         mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
     878          13 :         mysqli_resource->ptr = (void *)result;
     879          13 :         mysqli_resource->status = MYSQLI_STATUS_VALID;
     880          13 :         MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_result_class_entry);
     881             : }
     882             : /* }}} */
     883             : 
     884             : 
     885             : /* {{{ proto object mysqli_stmt_get_result(object link) U
     886             :    Buffer result set on client */
     887         592 : PHP_FUNCTION(mysqli_stmt_get_result)
     888             : {
     889             :         MYSQL_RES               *result;
     890             :         MYSQLI_RESOURCE *mysqli_resource;
     891             :         MY_STMT                 *stmt;
     892             :         zval                    *mysql_stmt;
     893             : 
     894         592 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
     895           5 :                 return;
     896             :         }
     897         587 :         MYSQLI_FETCH_RESOURCE_STMT(stmt, &mysql_stmt, MYSQLI_STATUS_VALID);
     898             : 
     899         585 :         if (!(result = mysqlnd_stmt_get_result(stmt->stmt))) {
     900           6 :                 MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
     901           6 :                 RETURN_FALSE;
     902             :         }
     903             : 
     904         579 :         mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
     905         579 :         mysqli_resource->ptr = (void *)result;
     906         579 :         mysqli_resource->status = MYSQLI_STATUS_VALID;
     907         579 :         MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_result_class_entry);
     908             : }
     909             : /* }}} */
     910             : #endif
     911             : 
     912             : 
     913             : /* {{{ proto object mysqli_get_warnings(object link) */
     914           5 : PHP_FUNCTION(mysqli_get_warnings)
     915             : {
     916             :         MY_MYSQL                        *mysql;
     917             :         zval                            *mysql_link;
     918             :         MYSQLI_RESOURCE         *mysqli_resource;
     919             :         MYSQLI_WARNING          *w;
     920             : 
     921           5 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
     922           0 :                 return;
     923             :         }
     924           5 :         MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
     925             : 
     926           5 :         if (mysql_warning_count(mysql->mysql)) {
     927             : #ifdef MYSQLI_USE_MYSQLND
     928           5 :                 w = php_get_warnings(mysql->mysql->data TSRMLS_CC);
     929             : #else
     930             :                 w = php_get_warnings(mysql->mysql TSRMLS_CC);
     931             : #endif
     932             :         } else {
     933           0 :                 RETURN_FALSE;
     934             :         }
     935           5 :         mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
     936           5 :         mysqli_resource->ptr = mysqli_resource->info = (void *)w;
     937           5 :         mysqli_resource->status = MYSQLI_STATUS_VALID;
     938           5 :         MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_warning_class_entry);
     939             : }
     940             : /* }}} */
     941             : 
     942             : 
     943             : /* {{{ proto object mysqli_stmt_get_warnings(object link) */
     944           0 : PHP_FUNCTION(mysqli_stmt_get_warnings)
     945             : {
     946             :         MY_STMT                         *stmt;
     947             :         zval                            *stmt_link;
     948             :         MYSQLI_RESOURCE         *mysqli_resource;
     949             :         MYSQLI_WARNING          *w;
     950             : 
     951           0 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &stmt_link, mysqli_stmt_class_entry) == FAILURE) {
     952           0 :                 return;
     953             :         }
     954           0 :         MYSQLI_FETCH_RESOURCE_STMT(stmt, &stmt_link, MYSQLI_STATUS_VALID);
     955             : 
     956           0 :         if (mysqli_stmt_warning_count(stmt->stmt)) {
     957           0 :                 w = php_get_warnings(mysqli_stmt_get_connection(stmt->stmt) TSRMLS_CC);
     958             :         } else {
     959           0 :                 RETURN_FALSE;
     960             :         }
     961           0 :         mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
     962           0 :         mysqli_resource->ptr = mysqli_resource->info = (void *)w;
     963           0 :         mysqli_resource->status = MYSQLI_STATUS_VALID;
     964           0 :         MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_warning_class_entry);
     965             : }
     966             : /* }}} */
     967             : 
     968             : 
     969             : #ifdef HAVE_MYSQLI_SET_CHARSET
     970             : /* {{{ proto bool mysqli_set_charset(object link, string csname)
     971             :    sets client character set */
     972          98 : PHP_FUNCTION(mysqli_set_charset)
     973             : {
     974             :         MY_MYSQL        *mysql;
     975             :         zval            *mysql_link;
     976             :         char            *cs_name;
     977             :         int                     csname_len;
     978             : 
     979          98 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, &cs_name, &csname_len) == FAILURE) {
     980           4 :                 return;
     981             :         }
     982          94 :         MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
     983             : 
     984          92 :         if (mysql_set_character_set(mysql->mysql, cs_name)) {
     985           2 :                 RETURN_FALSE;
     986             :         }
     987          90 :         RETURN_TRUE;
     988             : }
     989             : /* }}} */
     990             : #endif
     991             : 
     992             : #ifdef HAVE_MYSQLI_GET_CHARSET
     993             : /* {{{ proto object mysqli_get_charset(object link) U
     994             :    returns a character set object */
     995           5 : PHP_FUNCTION(mysqli_get_charset)
     996             : {
     997             :         MY_MYSQL                                *mysql;
     998             :         zval                                    *mysql_link;
     999           5 :         const char                              *name = NULL, *collation = NULL, *dir = NULL, *comment = NULL;
    1000             :         uint                                    minlength, maxlength, number, state;
    1001             : #if !defined(MYSQLI_USE_MYSQLND)
    1002             :         MY_CHARSET_INFO                 cs;
    1003             : #else
    1004             :         const MYSQLND_CHARSET   *cs;
    1005             : #endif
    1006             : 
    1007           5 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
    1008           2 :                 return;
    1009             :         }
    1010           3 :         MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
    1011             : 
    1012             : 
    1013             : #if !defined(MYSQLI_USE_MYSQLND)
    1014             :         mysql_get_character_set_info(mysql->mysql, &cs);
    1015             :         name = (char *)cs.csname;
    1016             :         collation = (char *)cs.name;
    1017             :         dir = (char *)cs.dir;
    1018             :         minlength = cs.mbminlen;
    1019             :         maxlength = cs.mbmaxlen;
    1020             :         number = cs.number;
    1021             :         state = cs.state;
    1022             :         comment = cs.comment;
    1023             : #else
    1024           2 :         cs = mysql->mysql->data->charset;
    1025           2 :         if (!cs) {
    1026           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "The connection has no charset associated");
    1027           0 :                 RETURN_NULL();
    1028             :         }
    1029           2 :         name = cs->name;
    1030           2 :         collation = cs->collation;
    1031           2 :         minlength = cs->char_minlen;
    1032           2 :         maxlength = cs->char_maxlen;
    1033           2 :         number = cs->nr;
    1034           2 :         comment = cs->comment;
    1035           2 :         state = 1;      /* all charsets are compiled in */
    1036             : #endif
    1037           2 :         object_init(return_value);
    1038             : 
    1039           2 :         add_property_string(return_value, "charset", (name) ? (char *)name : "", 1);
    1040           2 :         add_property_string(return_value, "collation",(collation) ? (char *)collation : "", 1);
    1041           2 :         add_property_string(return_value, "dir", (dir) ? (char *)dir : "", 1);
    1042           2 :         add_property_long(return_value, "min_length", minlength);
    1043           2 :         add_property_long(return_value, "max_length", maxlength);
    1044           2 :         add_property_long(return_value, "number", number);
    1045           2 :         add_property_long(return_value, "state", state);
    1046           2 :         add_property_string(return_value, "comment", (comment) ? (char *)comment : "", 1);
    1047             : }
    1048             : /* }}} */
    1049             : #endif
    1050             : 
    1051             : /*
    1052             :  * Local variables:
    1053             :  * tab-width: 4
    1054             :  * c-basic-offset: 4
    1055             :  * End:
    1056             :  * vim600: noet sw=4 ts=4 fdm=marker
    1057             :  * vim<600: noet sw=4 ts=4
    1058             :  */

Generated by: LCOV version 1.10

Generated at Tue, 25 Nov 2014 09:10:57 +0000 (2 days ago)

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