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

Generated by: LCOV version 1.10

Generated at Wed, 16 Apr 2014 12:47:50 +0000 (7 days ago)

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