Back to index

php5  5.3.10
Functions
mysqli_api.c File Reference
#include <signal.h>
#include "php.h"
#include "php_ini.h"
#include "php_globals.h"
#include "ext/standard/info.h"
#include "php_mysqli_structs.h"
#include "mysqli_priv.h"

Go to the source code of this file.

Functions

 PHP_FUNCTION (mysqli_affected_rows)
 PHP_FUNCTION (mysqli_autocommit)
static int mysqli_stmt_bind_param_do_bind (MY_STMT *stmt, unsigned int argc, unsigned int num_vars, zval ***args, unsigned int start, const char *const types TSRMLS_DC)
 PHP_FUNCTION (mysqli_stmt_bind_param)
static int mysqli_stmt_bind_result_do_bind (MY_STMT *stmt, zval ***args, unsigned int argc, unsigned int start TSRMLS_DC)
 PHP_FUNCTION (mysqli_stmt_bind_result)
 PHP_FUNCTION (mysqli_change_user)
 PHP_FUNCTION (mysqli_character_set_name)
void php_mysqli_close (MY_MYSQL *mysql, int close_type, int resource_status TSRMLS_DC)
 PHP_FUNCTION (mysqli_close)
 PHP_FUNCTION (mysqli_commit)
 PHP_FUNCTION (mysqli_data_seek)
 PHP_FUNCTION (mysqli_debug)
 PHP_FUNCTION (mysqli_dump_debug_info)
 PHP_FUNCTION (mysqli_errno)
 PHP_FUNCTION (mysqli_error)
static void php_mysqli_stmt_copy_it (zval ***copies, zval *original, uint param_count, uint current)
 PHP_FUNCTION (mysqli_stmt_execute)
void mysqli_stmt_fetch_libmysql (INTERNAL_FUNCTION_PARAMETERS)

Function Documentation

static int mysqli_stmt_bind_param_do_bind ( MY_STMT stmt,
unsigned int  argc,
unsigned int  num_vars,
zval ***  args,
unsigned int  start,
const char *const types  TSRMLS_DC 
) [static]

Definition at line 82 of file mysqli_api.c.

{
       int                         i, ofs;
       MYSQL_BIND           *bind;
       unsigned long rc;

       /* prevent leak if variables are already bound */
       if (stmt->param.var_cnt) {
              php_free_stmt_bind_buffer(stmt->param, FETCH_SIMPLE);
       }

       stmt->param.is_null = ecalloc(num_vars, sizeof(char));
       bind = (MYSQL_BIND *) ecalloc(num_vars, sizeof(MYSQL_BIND));

       ofs = 0;
       for (i = start; i < argc; i++) {

              /* set specified type */
              switch (types[ofs]) {
                     case 'd': /* Double */
                            bind[ofs].buffer_type = MYSQL_TYPE_DOUBLE;
                            bind[ofs].buffer = &Z_DVAL_PP(args[i]);
                            bind[ofs].is_null = &stmt->param.is_null[ofs];
                            break;

                     case 'i': /* Integer */
#if SIZEOF_LONG==8
                            bind[ofs].buffer_type = MYSQL_TYPE_LONGLONG;
#elif SIZEOF_LONG==4
                            bind[ofs].buffer_type = MYSQL_TYPE_LONG;
#endif
                            bind[ofs].buffer = &Z_LVAL_PP(args[i]);
                            bind[ofs].is_null = &stmt->param.is_null[ofs];
                            break;

                     case 'b': /* Blob (send data) */
                            bind[ofs].buffer_type = MYSQL_TYPE_LONG_BLOB;
                            /* don't initialize is_null and length to 0 because we use ecalloc */
                            break;

                     case 's': /* string */
                            bind[ofs].buffer_type = MYSQL_TYPE_VAR_STRING;
                            /* don't initialize buffer and buffer_length because we use ecalloc */
                            bind[ofs].is_null = &stmt->param.is_null[ofs];
                            break;

                     default:
                            php_error_docref(NULL TSRMLS_CC, E_WARNING, "Undefined fieldtype %c (parameter %d)", types[ofs], i+1);
                            rc = 1;
                            goto end_1;
              }
              ofs++;
       }
       rc = mysql_stmt_bind_param(stmt->stmt, bind);

end_1:
       if (rc) {
              efree(stmt->param.is_null);
       } else {
              stmt->param.var_cnt = num_vars;
              stmt->param.vars = (zval **)safe_emalloc(num_vars, sizeof(zval), 0);
              for (i = 0; i < num_vars; i++) {
                     if (bind[i].buffer_type  != MYSQL_TYPE_LONG_BLOB) {
                            Z_ADDREF_P(*args[i+start]);
                            stmt->param.vars[i] = *args[i+start];
                     } else {
                            stmt->param.vars[i] = NULL;
                     }
              }
       }
       efree(bind);

       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int mysqli_stmt_bind_result_do_bind ( MY_STMT stmt,
zval ***  args,
unsigned int  argc,
unsigned int start  TSRMLS_DC 
) [static]

Definition at line 283 of file mysqli_api.c.

{
       MYSQL_BIND    *bind;
       int                  i, ofs;
       int                  var_cnt = argc - start;
       long          col_type;
       ulong         rc;

       /* prevent leak if variables are already bound */
       if (stmt->result.var_cnt) {
              php_free_stmt_bind_buffer(stmt->result, FETCH_RESULT);
       }

       bind = (MYSQL_BIND *)ecalloc(var_cnt, sizeof(MYSQL_BIND));
       {
              int size;
              char *p= emalloc(size= var_cnt * (sizeof(char) + sizeof(VAR_BUFFER)));
              stmt->result.buf = (VAR_BUFFER *) p;
              stmt->result.is_null = p + var_cnt * sizeof(VAR_BUFFER);
              memset(p, 0, size);
       }

       for (i=start; i < var_cnt + start ; i++) {
              ofs = i - start;
              col_type = (stmt->stmt->fields) ? stmt->stmt->fields[ofs].type : MYSQL_TYPE_STRING;

              switch (col_type) {
                     case MYSQL_TYPE_DOUBLE:
                     case MYSQL_TYPE_FLOAT:
                            convert_to_double_ex(args[i]);
                            stmt->result.buf[ofs].type = IS_DOUBLE;
                            stmt->result.buf[ofs].buflen = sizeof(double);

                            /* allocate buffer for double */
                            stmt->result.buf[ofs].val = (char *)emalloc(sizeof(double));
                            bind[ofs].buffer_type = MYSQL_TYPE_DOUBLE;
                            bind[ofs].buffer = stmt->result.buf[ofs].val;
                            bind[ofs].is_null = &stmt->result.is_null[ofs];
                            break;

                     case MYSQL_TYPE_NULL:
                            stmt->result.buf[ofs].type = IS_NULL;
                            /*
                              don't initialize to 0 :
                              1. stmt->result.buf[ofs].buflen
                              2. bind[ofs].buffer
                              3. bind[ofs].buffer_length
                              because memory was allocated with ecalloc
                            */
                            bind[ofs].buffer_type = MYSQL_TYPE_NULL;
                            bind[ofs].is_null = &stmt->result.is_null[ofs];
                            break;

                     case MYSQL_TYPE_SHORT:
                     case MYSQL_TYPE_TINY:
                     case MYSQL_TYPE_LONG:
                     case MYSQL_TYPE_INT24:
                     case MYSQL_TYPE_YEAR:
                            convert_to_long_ex(args[i]);
                            stmt->result.buf[ofs].type = IS_LONG;
                            /* don't set stmt->result.buf[ofs].buflen to 0, we used ecalloc */
                            stmt->result.buf[ofs].val = (char *)emalloc(sizeof(int));
                            bind[ofs].buffer_type = MYSQL_TYPE_LONG;
                            bind[ofs].buffer = stmt->result.buf[ofs].val;
                            bind[ofs].is_null = &stmt->result.is_null[ofs];
                            bind[ofs].is_unsigned = (stmt->stmt->fields[ofs].flags & UNSIGNED_FLAG) ? 1 : 0;
                            break;

                     case MYSQL_TYPE_LONGLONG:
#if MYSQL_VERSION_ID > 50002 || defined(MYSQLI_USE_MYSQLND)
                     case MYSQL_TYPE_BIT:
#endif
                            stmt->result.buf[ofs].type = IS_STRING;
                            stmt->result.buf[ofs].buflen = sizeof(my_ulonglong);
                            stmt->result.buf[ofs].val = (char *)emalloc(stmt->result.buf[ofs].buflen);
                            bind[ofs].buffer_type = col_type;
                            bind[ofs].buffer = stmt->result.buf[ofs].val;
                            bind[ofs].is_null = &stmt->result.is_null[ofs];
                            bind[ofs].buffer_length = stmt->result.buf[ofs].buflen;
                            bind[ofs].is_unsigned = (stmt->stmt->fields[ofs].flags & UNSIGNED_FLAG) ? 1 : 0;
                            bind[ofs].length = &stmt->result.buf[ofs].output_len;
                            break;

                     case MYSQL_TYPE_DATE:
                     case MYSQL_TYPE_TIME:
                     case MYSQL_TYPE_DATETIME:
                     case MYSQL_TYPE_NEWDATE:
                     case MYSQL_TYPE_VAR_STRING:
                     case MYSQL_TYPE_STRING:
                     case MYSQL_TYPE_TINY_BLOB:
                     case MYSQL_TYPE_BLOB:
                     case MYSQL_TYPE_MEDIUM_BLOB:
                     case MYSQL_TYPE_LONG_BLOB:
                     case MYSQL_TYPE_TIMESTAMP:
                     case MYSQL_TYPE_DECIMAL:
                     case MYSQL_TYPE_GEOMETRY:
#ifdef FIELD_TYPE_NEWDECIMAL
                     case MYSQL_TYPE_NEWDECIMAL:
#endif
                     {
#if MYSQL_VERSION_ID >= 50107
                            /* Changed to my_bool in MySQL 5.1. See MySQL Bug #16144 */
                            my_bool tmp;
#else
                            uint tmp = 0;
#endif
                            stmt->result.buf[ofs].type = IS_STRING;
                            /*
                                   If the user has called $stmt->store_result() then we have asked
                                   max_length to be updated. this is done only for BLOBS because we don't want to allocate
                                   big chunkgs of memory 2^16 or 2^24
                            */
                            if (stmt->stmt->fields[ofs].max_length == 0 &&
                                   !mysql_stmt_attr_get(stmt->stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &tmp) && !tmp)
                            {
                                   /*
                                     Allocate directly 256 because it's easier to allocate a bit more
                                     than update max length even for text columns. Try SELECT UNION SELECT UNION with
                                     different lengths and you will see that we get different lengths in stmt->stmt->fields[ofs].length
                                     The just take 256 and saves us from realloc-ing.
                                   */
                                   stmt->result.buf[ofs].buflen =
                                          (stmt->stmt->fields) ? (stmt->stmt->fields[ofs].length) ? stmt->stmt->fields[ofs].length + 1: 256: 256;

                            } else {
                                   /*
                                          the user has called store_result(). if he does not there is no way to determine the
                                          libmysql does not allow us to allocate 0 bytes for a buffer so we try 1
                                   */
                                   if (!(stmt->result.buf[ofs].buflen = stmt->stmt->fields[ofs].max_length))
                                          ++stmt->result.buf[ofs].buflen;
                            }
                            stmt->result.buf[ofs].val = (char *)emalloc(stmt->result.buf[ofs].buflen);
                            bind[ofs].buffer_type = MYSQL_TYPE_STRING;
                            bind[ofs].buffer = stmt->result.buf[ofs].val;
                            bind[ofs].is_null = &stmt->result.is_null[ofs];
                            bind[ofs].buffer_length = stmt->result.buf[ofs].buflen;
                            bind[ofs].length = &stmt->result.buf[ofs].output_len;
                            break;
                     }
                     default:
                            php_error_docref(NULL TSRMLS_CC, E_WARNING, "Server returned unknown type %ld. Probably your client library is incompatible with the server version you use!", col_type);
                            break;
              }
       }

       rc = mysql_stmt_bind_result(stmt->stmt, bind);
       MYSQLI_REPORT_STMT_ERROR(stmt->stmt);

       if (rc) {
              /* dont close the statement or subsequent usage (for example ->execute()) will lead to crash */
              for (i=0; i < var_cnt ; i++) {
                     if (stmt->result.buf[i].val) {
                            efree(stmt->result.buf[i].val);
                     }
              }
              /* Don't free stmt->result.is_null because is_null & buf are one block of memory  */
              efree(stmt->result.buf);
       } else {
              stmt->result.var_cnt = var_cnt;
              stmt->result.vars = (zval **)safe_emalloc((var_cnt), sizeof(zval), 0);
              for (i = start; i < var_cnt+start; i++) {
                     ofs = i-start;
                     Z_ADDREF_PP(args[i]);
                     stmt->result.vars[ofs] = *args[i];
              }
       }
       efree(bind);

       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 851 of file mysqli_api.c.

{
       MY_STMT              *stmt;
       zval                 *mysql_stmt;
       unsigned int  i;
       ulong                ret;
       unsigned int  uval;
       my_ulonglong  llval;


       if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
              return;
       }
       MYSQLI_FETCH_RESOURCE_STMT(stmt, &mysql_stmt, MYSQLI_STATUS_VALID);

       /* reset buffers */
       for (i = 0; i < stmt->result.var_cnt; i++) {
              if (stmt->result.buf[i].type == IS_STRING) {
                     memset(stmt->result.buf[i].val, 0, stmt->result.buf[i].buflen);
              }
       }
       ret = mysql_stmt_fetch(stmt->stmt);
#ifdef MYSQL_DATA_TRUNCATED
       if (!ret || ret == MYSQL_DATA_TRUNCATED) {
#else
       if (!ret) {
#endif
              for (i = 0; i < stmt->result.var_cnt; i++) {
                     /*
                       QQ: Isn't it quite better to call zval_dtor(). What if the user has
                       assigned a resource, or an array to the bound variable? We are going
                       to leak probably. zval_dtor() will handle also Unicode/Non-unicode mode.
                     */
                     /* Even if the string is of length zero there is one byte alloced so efree() in all cases */
                     if (Z_TYPE_P(stmt->result.vars[i]) == IS_STRING) {
                            efree(stmt->result.vars[i]->value.str.val);
                     }
                     if (!stmt->result.is_null[i]) {
                            switch (stmt->result.buf[i].type) {
                                   case IS_LONG:
                                          if ((stmt->stmt->fields[i].type == MYSQL_TYPE_LONG)
                                              && (stmt->stmt->fields[i].flags & UNSIGNED_FLAG))
                                          {
                                                 /* unsigned int (11) */
                                                 uval= *(unsigned int *) stmt->result.buf[i].val;
#if SIZEOF_LONG==4
                                                 if (uval > INT_MAX) {
                                                        char *tmp, *p;
                                                        int j=10;
                                                        tmp= emalloc(11);
                                                        p= &tmp[9];
                                                        do {
                                                               *p-- = (uval % 10) + 48;
                                                               uval = uval / 10;
                                                        } while (--j > 0);
                                                        tmp[10]= '\0';
                                                        /* unsigned int > INT_MAX is 10 digits - ALWAYS */
                                                        ZVAL_STRINGL(stmt->result.vars[i], tmp, 10, 0);
                                                        break;
                                                 }
#endif
                                          }
                                          if (stmt->stmt->fields[i].flags & UNSIGNED_FLAG) {
                                                 ZVAL_LONG(stmt->result.vars[i], *(unsigned int *)stmt->result.buf[i].val);
                                          } else {
                                                 ZVAL_LONG(stmt->result.vars[i], *(int *)stmt->result.buf[i].val);
                                          }
                                          break;
                                   case IS_DOUBLE:
                                          ZVAL_DOUBLE(stmt->result.vars[i], *(double *)stmt->result.buf[i].val);
                                          break;
                                   case IS_STRING:
                                          if (stmt->stmt->bind[i].buffer_type == MYSQL_TYPE_LONGLONG
#if MYSQL_VERSION_ID > 50002
                                           || stmt->stmt->bind[i].buffer_type == MYSQL_TYPE_BIT
#endif
                                           ) {
                                                 my_bool uns= (stmt->stmt->fields[i].flags & UNSIGNED_FLAG)? 1:0;
#if MYSQL_VERSION_ID > 50002
                                                 if (stmt->stmt->bind[i].buffer_type == MYSQL_TYPE_BIT) {
                                                        switch (stmt->result.buf[i].output_len) {
                                                               case 8:llval = (my_ulonglong)  bit_uint8korr(stmt->result.buf[i].val);break;
                                                               case 7:llval = (my_ulonglong)  bit_uint7korr(stmt->result.buf[i].val);break;
                                                               case 6:llval = (my_ulonglong)  bit_uint6korr(stmt->result.buf[i].val);break;
                                                               case 5:llval = (my_ulonglong)  bit_uint5korr(stmt->result.buf[i].val);break;
                                                               case 4:llval = (my_ulonglong)  bit_uint4korr(stmt->result.buf[i].val);break;
                                                               case 3:llval = (my_ulonglong)  bit_uint3korr(stmt->result.buf[i].val);break;
                                                               case 2:llval = (my_ulonglong)  bit_uint2korr(stmt->result.buf[i].val);break;
                                                               case 1:llval = (my_ulonglong)  uint1korr(stmt->result.buf[i].val);break;
                                                        }
                                                 } else
#endif
                                                 {
                                                        llval= *(my_ulonglong *) stmt->result.buf[i].val;
                                                 }
#if SIZEOF_LONG==8
                                                 if (uns && llval > 9223372036854775807L) {
#elif SIZEOF_LONG==4
                                                 if ((uns && llval > L64(2147483647)) ||
                                                        (!uns && (( L64(2147483647) < (my_longlong) llval) ||
                                                        (L64(-2147483648) > (my_longlong) llval))))
                                                 {
#endif
                                                        char tmp[22];
                                                        /* even though lval is declared as unsigned, the value
                                                         * may be negative. Therefor we cannot use MYSQLI_LLU_SPEC and must
                                                         * use MYSQLI_LL_SPEC.
                                                         */
                                                        snprintf(tmp, sizeof(tmp), (stmt->stmt->fields[i].flags & UNSIGNED_FLAG)? MYSQLI_LLU_SPEC : MYSQLI_LL_SPEC, llval);
                                                        ZVAL_STRING(stmt->result.vars[i], tmp, 1);
                                                 } else {
                                                        ZVAL_LONG(stmt->result.vars[i], llval);
                                                 }
                                          } else {
#if defined(MYSQL_DATA_TRUNCATED) && MYSQL_VERSION_ID > 50002
                                                 if (ret == MYSQL_DATA_TRUNCATED && *(stmt->stmt->bind[i].error) != 0) {
                                                        /* result was truncated */
                                                        ZVAL_STRINGL(stmt->result.vars[i], stmt->result.buf[i].val,
                                                                              stmt->stmt->bind[i].buffer_length, 1);
                                                 } else {
#else
                                                 {
#endif
                                                        ZVAL_STRINGL(stmt->result.vars[i], stmt->result.buf[i].val,
                                                                              stmt->result.buf[i].output_len, 1);
                                                 }
                                          }
                                          break;
                                   default:
                                          break;
                            }
                     } else {
                            ZVAL_NULL(stmt->result.vars[i]);
                     }
              }
       } else {

Here is the call graph for this function:

PHP_FUNCTION ( mysqli_affected_rows  )

Definition at line 38 of file mysqli_api.c.

{
       MY_MYSQL             *mysql;
       zval                 *mysql_link;
       my_ulonglong  rc;

       if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
              return;
       }

       MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);

       rc = mysql_affected_rows(mysql->mysql);
       if (rc == (my_ulonglong) -1) {
              RETURN_LONG(-1);
       }
       MYSQLI_RETURN_LONG_LONG(rc);
}

Here is the call graph for this function:

PHP_FUNCTION ( mysqli_autocommit  )

Definition at line 61 of file mysqli_api.c.

{
       MY_MYSQL      *mysql;
       zval          *mysql_link;
       zend_bool     automode;

       if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ob", &mysql_link, mysqli_link_class_entry, &automode) == FAILURE) {
              return;
       }
       MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);

       if (mysql_autocommit(mysql->mysql, (my_bool)automode)) {
              RETURN_FALSE;
       }
       RETURN_TRUE;
}

Here is the call graph for this function:

PHP_FUNCTION ( mysqli_stmt_bind_param  )

Definition at line 213 of file mysqli_api.c.

{
       zval                 ***args;
       int                         argc = ZEND_NUM_ARGS();
       int                         num_vars;
       int                         start = 2;
       MY_STMT                     *stmt;
       zval                 *mysql_stmt;
       char                 *types;
       int                         types_len;
       unsigned long rc;

       /* calculate and check number of parameters */
       if (argc < 2) {
              /* there has to be at least one pair */
              WRONG_PARAM_COUNT;
       }

       if (zend_parse_method_parameters((getThis()) ? 1:2 TSRMLS_CC, getThis(), "Os", &mysql_stmt, mysqli_stmt_class_entry,
                                                               &types, &types_len) == FAILURE) {
              return;
       }

       MYSQLI_FETCH_RESOURCE_STMT(stmt, &mysql_stmt, MYSQLI_STATUS_VALID);

       num_vars = argc - 1;
       if (getThis()) {
              start = 1;
       } else {
              /* ignore handle parameter in procedural interface*/
              --num_vars;
       }
       if (!types_len) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid type or no types specified");
              RETURN_FALSE;
       }

       if (types_len != argc - start) {
              /* number of bind variables doesn't match number of elements in type definition string */
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of elements in type definition string doesn't match number of bind variables");
              RETURN_FALSE;
       }

       if (types_len != mysql_stmt_param_count(stmt->stmt)) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of variables doesn't match number of parameters in prepared statement");
              RETURN_FALSE;
       }

       args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);

       if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
              zend_wrong_param_count(TSRMLS_C);
              rc = 1;
       } else {
              rc = mysqli_stmt_bind_param_do_bind(stmt, argc, num_vars, args, start, types TSRMLS_CC);
              MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
       }

       efree(args);

       RETURN_BOOL(!rc);
}

Here is the call graph for this function:

PHP_FUNCTION ( mysqli_stmt_bind_result  )

Definition at line 473 of file mysqli_api.c.

{
       zval          ***args;
       int                  argc = ZEND_NUM_ARGS();
       int                  start = 1;
       ulong         rc;
       MY_STMT              *stmt;
       zval          *mysql_stmt;

       if (getThis()) {
              start = 0;
       }

       if (zend_parse_method_parameters((getThis()) ? 0:1 TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
              return;
       }

       MYSQLI_FETCH_RESOURCE_STMT(stmt, &mysql_stmt, MYSQLI_STATUS_VALID);

       if (argc < (getThis() ? 1 : 2)) {
              WRONG_PARAM_COUNT;
       }

       if ((argc - start) != mysql_stmt_field_count(stmt->stmt)) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of bind variables doesn't match number of fields in prepared statement");
              RETURN_FALSE;
       }

       args = (zval ***)safe_emalloc(argc, sizeof(zval **), 0);

       if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
              efree(args);
              WRONG_PARAM_COUNT;
       }

       rc = mysqli_stmt_bind_result_do_bind(stmt, args, argc, start TSRMLS_CC);

       efree(args);

       RETURN_BOOL(!rc);
}

Here is the call graph for this function:

PHP_FUNCTION ( mysqli_change_user  )

Definition at line 518 of file mysqli_api.c.

{
       MY_MYSQL      *mysql;
       zval          *mysql_link = NULL;
       char          *user, *password, *dbname;
       int                  user_len, password_len, dbname_len;
       ulong         rc;
#if !defined(MYSQLI_USE_MYSQLND) && defined(HAVE_MYSQLI_SET_CHARSET)
       const         CHARSET_INFO * old_charset;
#endif

       if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osss", &mysql_link, mysqli_link_class_entry, &user, &user_len, &password, &password_len, &dbname, &dbname_len) == FAILURE) {
              return;
       }
       MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);

#if !defined(MYSQLI_USE_MYSQLND) && defined(HAVE_MYSQLI_SET_CHARSET)
       old_charset = mysql->mysql->charset;
#endif

       rc = mysql_change_user(mysql->mysql, user, password, dbname);
       MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);

       if (rc) {
              RETURN_FALSE;
       }
#if !defined(MYSQLI_USE_MYSQLND) && defined(HAVE_MYSQLI_SET_CHARSET)
       if (mysql_get_server_version(mysql->mysql) < 501023L) {
              /*
                Request the current charset, or it will be reset to the system one.
                5.0 doesn't support it. Support added in 5.1.23 by fixing the following bug :
                Bug #30472 libmysql doesn't reset charset, insert_id after succ. mysql_change_user() call
              */
              rc = mysql_set_character_set(mysql->mysql, old_charset->csname);
       }
#endif

       RETURN_TRUE;
}

Here is the call graph for this function:

PHP_FUNCTION ( mysqli_character_set_name  )

Definition at line 561 of file mysqli_api.c.

{
       MY_MYSQL      *mysql;
       zval          *mysql_link;

       if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
              return;
       }

       MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);

       RETURN_STRING((char *)mysql_character_set_name(mysql->mysql), 1);
}

Here is the call graph for this function:

Definition at line 611 of file mysqli_api.c.

Here is the call graph for this function:

PHP_FUNCTION ( mysqli_commit  )

Definition at line 633 of file mysqli_api.c.

{
       MY_MYSQL      *mysql;
       zval          *mysql_link;

       if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
              return;
       }
       MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
       if (mysql_commit(mysql->mysql)) {
              RETURN_FALSE;
       }
       RETURN_TRUE;
}

Here is the call graph for this function:

PHP_FUNCTION ( mysqli_data_seek  )

Definition at line 651 of file mysqli_api.c.

{
       MYSQL_RES     *result;
       zval          *mysql_result;
       long          offset;

       if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &mysql_result, mysqli_result_class_entry, &offset) == FAILURE) {
              return;
       }

       MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);

       if (mysqli_result_is_unbuffered(result)) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Function cannot be used with MYSQL_USE_RESULT");
              RETURN_FALSE;
       }

       if (offset < 0 || offset >= mysql_num_rows(result)) {
              RETURN_FALSE;
       }

       mysql_data_seek(result, offset);
       RETURN_TRUE;
}

Here is the call graph for this function:

PHP_FUNCTION ( mysqli_debug  )

Definition at line 679 of file mysqli_api.c.

{
       char   *debug;
       int           debug_len;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &debug, &debug_len) == FAILURE) {
              return;
       }

       mysql_debug(debug);
       RETURN_TRUE;
}

Here is the call graph for this function:

PHP_FUNCTION ( mysqli_dump_debug_info  )

Definition at line 696 of file mysqli_api.c.

{
       MY_MYSQL      *mysql;
       zval          *mysql_link;

       if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
              return;
       }
       MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);

       RETURN_BOOL(!mysql_dump_debug_info(mysql->mysql))
}

Here is the call graph for this function:

PHP_FUNCTION ( mysqli_errno  )

Definition at line 712 of file mysqli_api.c.

{
       MY_MYSQL      *mysql;
       zval          *mysql_link;

       if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
              return;
       }
       MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
       RETURN_LONG(mysql_errno(mysql->mysql));
}

Here is the call graph for this function:

PHP_FUNCTION ( mysqli_error  )

Definition at line 727 of file mysqli_api.c.

{
       MY_MYSQL      *mysql;
       zval          *mysql_link;

       if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
              return;
       }
       MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
       RETURN_STRING((char *)mysql_error(mysql->mysql),1);
}

Here is the call graph for this function:

PHP_FUNCTION ( mysqli_stmt_execute  )

Definition at line 758 of file mysqli_api.c.

{
       MY_STMT              *stmt;
       zval          *mysql_stmt;
#ifndef MYSQLI_USE_MYSQLND
       unsigned int  i;
       zval          **copies = NULL;
#endif

       if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
              return;
       }
       MYSQLI_FETCH_RESOURCE_STMT(stmt, &mysql_stmt, MYSQLI_STATUS_VALID);

#ifndef MYSQLI_USE_MYSQLND
       if (stmt->param.var_cnt) {
              int j;
              for (i = 0; i < stmt->param.var_cnt; i++) {
                     for (j = i + 1; j < stmt->param.var_cnt; j++) {
                            /* Oops, someone binding the same variable - clone */
                            if (stmt->param.vars[j] == stmt->param.vars[i] && stmt->param.vars[i]) {
                                   php_mysqli_stmt_copy_it(&copies, stmt->param.vars[i], stmt->param.var_cnt, i);
                                   break;
                            }
                     }
              }
       }
       for (i = 0; i < stmt->param.var_cnt; i++) {
              if (stmt->param.vars[i]) {
                     if ( !(stmt->param.is_null[i] = (stmt->param.vars[i]->type == IS_NULL)) ) {
                            zval *the_var = copies && copies[i]? copies[i]:stmt->param.vars[i];
                            switch (stmt->stmt->params[i].buffer_type) {
                                   case MYSQL_TYPE_VAR_STRING:
                                          if (the_var == stmt->param.vars[i] && Z_TYPE_P(stmt->param.vars[i]) != IS_STRING) {
                                                 php_mysqli_stmt_copy_it(&copies, stmt->param.vars[i], stmt->param.var_cnt, i);
                                                 the_var = copies[i];
                                          }
                                          convert_to_string_ex(&the_var);
                                          stmt->stmt->params[i].buffer = Z_STRVAL_P(the_var);
                                          stmt->stmt->params[i].buffer_length = Z_STRLEN_P(the_var);
                                          break;
                                   case MYSQL_TYPE_DOUBLE:
                                          if (the_var == stmt->param.vars[i] && Z_TYPE_P(stmt->param.vars[i]) != IS_DOUBLE) {
                                                 php_mysqli_stmt_copy_it(&copies, stmt->param.vars[i], stmt->param.var_cnt, i);
                                                 the_var = copies[i];
                                          }
                                          convert_to_double_ex(&the_var);
                                          stmt->stmt->params[i].buffer = &Z_DVAL_P(the_var);
                                          break;
                                   case MYSQL_TYPE_LONGLONG:
                                   case MYSQL_TYPE_LONG:
                                          if (the_var == stmt->param.vars[i] && Z_TYPE_P(stmt->param.vars[i]) != IS_LONG) {
                                                 php_mysqli_stmt_copy_it(&copies, stmt->param.vars[i], stmt->param.var_cnt, i);
                                                 the_var = copies[i];
                                          }
                                          convert_to_long_ex(&the_var);
                                          stmt->stmt->params[i].buffer = &Z_LVAL_P(the_var);
                                          break;
                                   default:
                                          break;
                            }
                     }
              }
       }
#endif

       if (mysql_stmt_execute(stmt->stmt)) {
              MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
              RETVAL_FALSE;
       } else {
              RETVAL_TRUE;
       }

#ifndef MYSQLI_USE_MYSQLND
       if (copies) {
              for (i = 0; i < stmt->param.var_cnt; i++) {
                     if (copies[i]) {
                            zval_ptr_dtor(&copies[i]);
                     }
              }
              efree(copies);
       }
#endif

       if (MyG(report_mode) & MYSQLI_REPORT_INDEX) {
              php_mysqli_report_index(stmt->query, mysqli_stmt_server_status(stmt->stmt) TSRMLS_CC);
       }
}

Here is the call graph for this function:

void php_mysqli_close ( MY_MYSQL mysql,
int  close_type,
int resource_status  TSRMLS_DC 
)

Definition at line 578 of file mysqli_api.c.

{
       if (resource_status > MYSQLI_STATUS_INITIALIZED) {
              MyG(num_links)--;
       }

       if (!mysql->persistent) {
              mysqli_close(mysql->mysql, close_type);
       } else {
              zend_rsrc_list_entry *le;
              if (zend_hash_find(&EG(persistent_list), mysql->hash_key, strlen(mysql->hash_key) + 1, (void **)&le) == SUCCESS) {
                     if (Z_TYPE_P(le) == php_le_pmysqli()) {
                            mysqli_plist_entry *plist = (mysqli_plist_entry *) le->ptr;
#if defined(MYSQLI_USE_MYSQLND)
                            mysqlnd_end_psession(mysql->mysql);
#endif
                            zend_ptr_stack_push(&plist->free_links, mysql->mysql);

                            MyG(num_active_persistent)--;
                            MyG(num_inactive_persistent)++;
                     }
              }
              mysql->persistent = FALSE;
       }
       mysql->mysql = NULL;

       php_clear_mysql(mysql);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void php_mysqli_stmt_copy_it ( zval ***  copies,
zval *  original,
uint  param_count,
uint  current 
) [static]

Definition at line 743 of file mysqli_api.c.

{
       if (!*copies) {
              *copies = ecalloc(param_count, sizeof(zval *));
       }
       MAKE_STD_ZVAL((*copies)[current]);
       *(*copies)[current] = *original;
       Z_SET_REFCOUNT_P((*copies)[current], 1);
       zval_copy_ctor((*copies)[current]);
}

Here is the caller graph for this function: