Back to index

php5  5.3.10
Defines | Functions | Variables
mysqli_priv.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define REGISTER_MYSQLI_CLASS_ENTRY(name, mysqli_entry, class_functions)
#define PHP_MYSQLI_EXPORT(__type)   PHP_MYSQLI_API __type
#define MYSQLI_DISABLE_MQ
#define MYSQLI_ENABLE_MQ
#define MYSQLI_RETURN_LONG_LONG(__val)
#define MYSQLI_STORE_RESULT   0
#define MYSQLI_USE_RESULT   1
#define MYSQLI_ASYNC   0
#define MYSQLI_ASSOC   1
#define MYSQLI_NUM   2
#define MYSQLI_BOTH   3
#define FETCH_SIMPLE   1
#define FETCH_RESULT   2
#define MYSQLI_REPORT_OFF   0
#define MYSQLI_REPORT_ERROR   1
#define MYSQLI_REPORT_STRICT   2
#define MYSQLI_REPORT_INDEX   4
#define MYSQLI_REPORT_CLOSE   8
#define MYSQLI_REPORT_ALL   255
#define MYSQLI_REPORT_MYSQL_ERROR(mysql)
#define MYSQLI_REPORT_STMT_ERROR(stmt)

Functions

int php_le_pmysqli (void)
void php_mysqli_dtor_p_elements (void *data)
void php_mysqli_close (MY_MYSQL *mysql, int close_type, int resource_status TSRMLS_DC)
void php_mysqli_fetch_into_hash (INTERNAL_FUNCTION_PARAMETERS, int override_flag, int into_object)
void php_clear_stmt_bind (MY_STMT *stmt TSRMLS_DC)
void php_clear_mysql (MY_MYSQL *)
MYSQLI_WARNING * php_get_warnings (MYSQL *mysql TSRMLS_DC)
void php_clear_warnings (MYSQLI_WARNING *w)
void php_free_stmt_bind_buffer (BIND_BUFFER bbuf, int type)
void php_mysqli_report_error (const char *sqlstate, int errorno, const char *error TSRMLS_DC)
void php_mysqli_report_index (const char *query, unsigned int status TSRMLS_DC)
void php_set_local_infile_handler_default (MY_MYSQL *)
void php_mysqli_throw_sql_exception (char *sqlstate, int errorno TSRMLS_DC, char *format,...)
 PHP_MYSQLI_EXPORT (zend_object_value) mysqli_objects_new(zend_class_entry *TSRMLS_DC)
void mysqli_common_connect (INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_connect, zend_bool in_ctor)
void php_mysqli_init (INTERNAL_FUNCTION_PARAMETERS)

Variables

const zend_function_entry mysqli_functions []
const zend_function_entry mysqli_link_methods []
const zend_function_entry mysqli_stmt_methods []
const zend_function_entry mysqli_result_methods []
const zend_function_entry mysqli_driver_methods []
const zend_function_entry mysqli_warning_methods []
const zend_function_entry mysqli_exception_methods []
const mysqli_property_entry mysqli_link_property_entries []
const mysqli_property_entry mysqli_result_property_entries []
const mysqli_property_entry mysqli_stmt_property_entries []
const mysqli_property_entry mysqli_driver_property_entries []
const mysqli_property_entry mysqli_warning_property_entries []
zend_property_info mysqli_link_property_info_entries []
zend_property_info mysqli_result_property_info_entries []
zend_property_info mysqli_stmt_property_info_entries []
zend_property_info mysqli_driver_property_info_entries []
zend_property_info mysqli_warning_property_info_entries []

Define Documentation

#define FETCH_RESULT   2

Definition at line 132 of file mysqli_priv.h.

#define FETCH_SIMPLE   1

Definition at line 131 of file mysqli_priv.h.

#define MYSQLI_ASSOC   1

Definition at line 126 of file mysqli_priv.h.

#define MYSQLI_ASYNC   0

Definition at line 122 of file mysqli_priv.h.

#define MYSQLI_BOTH   3

Definition at line 128 of file mysqli_priv.h.

Value:
if (mysql->multi_query) { \
       mysql_set_server_option(mysql->mysql, MYSQL_OPTION_MULTI_STATEMENTS_OFF); \
       mysql->multi_query = 0; \
}

Definition at line 93 of file mysqli_priv.h.

Value:
if (!mysql->multi_query) { \
       mysql_set_server_option(mysql->mysql, MYSQL_OPTION_MULTI_STATEMENTS_ON); \
       mysql->multi_query = 1; \
}

Definition at line 98 of file mysqli_priv.h.

#define MYSQLI_NUM   2

Definition at line 127 of file mysqli_priv.h.

#define MYSQLI_REPORT_ALL   255

Definition at line 140 of file mysqli_priv.h.

#define MYSQLI_REPORT_CLOSE   8

Definition at line 139 of file mysqli_priv.h.

#define MYSQLI_REPORT_ERROR   1

Definition at line 136 of file mysqli_priv.h.

#define MYSQLI_REPORT_INDEX   4

Definition at line 138 of file mysqli_priv.h.

#define MYSQLI_REPORT_MYSQL_ERROR (   mysql)
Value:
if ((MyG(report_mode) & MYSQLI_REPORT_ERROR) && mysql_errno(mysql)) { \
       php_mysqli_report_error(mysql_sqlstate(mysql), mysql_errno(mysql), mysql_error(mysql) TSRMLS_CC); \
}

Definition at line 142 of file mysqli_priv.h.

#define MYSQLI_REPORT_OFF   0

Definition at line 135 of file mysqli_priv.h.

#define MYSQLI_REPORT_STMT_ERROR (   stmt)
Value:
if ((MyG(report_mode) & MYSQLI_REPORT_ERROR) && mysql_stmt_errno(stmt)) { \
       php_mysqli_report_error(mysql_stmt_sqlstate(stmt), mysql_stmt_errno(stmt), mysql_stmt_error(stmt) TSRMLS_CC); \
}

Definition at line 147 of file mysqli_priv.h.

#define MYSQLI_REPORT_STRICT   2

Definition at line 137 of file mysqli_priv.h.

#define MYSQLI_RETURN_LONG_LONG (   __val)
Value:
{ \
       if ((__val) < LONG_MAX) {          \
              RETURN_LONG((long) (__val));              \
       } else {                           \
              char *ret;                  \
              /* always used with my_ulonglong -> %llu */ \
              int l = spprintf(&ret, 0, MYSQLI_LLU_SPEC, (__val));    \
              RETURN_STRINGL(ret, l, 0);         \
       }                                  \
}

Definition at line 104 of file mysqli_priv.h.

#define MYSQLI_STORE_RESULT   0

Definition at line 116 of file mysqli_priv.h.

#define MYSQLI_USE_RESULT   1

Definition at line 117 of file mysqli_priv.h.

#define PHP_MYSQLI_EXPORT (   __type)    PHP_MYSQLI_API __type

Definition at line 88 of file mysqli_priv.h.

#define REGISTER_MYSQLI_CLASS_ENTRY (   name,
  mysqli_entry,
  class_functions 
)
Value:
{ \
       zend_class_entry tmp_ce; \
       INIT_CLASS_ENTRY(tmp_ce, name,class_functions); \
       tmp_ce.create_object = mysqli_objects_new; \
       mysqli_entry = zend_register_internal_class(&tmp_ce TSRMLS_CC); \
} \

Definition at line 81 of file mysqli_priv.h.


Function Documentation

void mysqli_common_connect ( INTERNAL_FUNCTION_PARAMETERS  ,
zend_bool  is_real_connect,
zend_bool  in_ctor 
)

Definition at line 59 of file mysqli_nonapi.c.

{
       MY_MYSQL                    *mysql = NULL;
       MYSQLI_RESOURCE             *mysqli_resource = NULL;
       zval                        *object = getThis();
       char                        *hostname = NULL, *username=NULL, *passwd=NULL, *dbname=NULL, *socket=NULL;
       int                                hostname_len = 0, username_len = 0, passwd_len = 0, dbname_len = 0, socket_len = 0;
       zend_bool                   persistent = FALSE;
       long                        port = 0, flags = 0;
       uint                        hash_len;
       char                        *hash_key = NULL;
       zend_bool                   new_connection = FALSE;
       zend_rsrc_list_entry *le;
       mysqli_plist_entry *plist = NULL;
       zend_bool                   self_alloced = 0;


#if !defined(MYSQL_USE_MYSQLND)
       if ((MYSQL_VERSION_ID / 100) != (mysql_get_client_version() / 100)) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING,
                                          "Headers and client library minor version mismatch. Headers:%d Library:%ld",
                                          MYSQL_VERSION_ID, mysql_get_client_version());
       }
#endif

       if (getThis() && !ZEND_NUM_ARGS() && in_ctor) {
              php_mysqli_init(INTERNAL_FUNCTION_PARAM_PASSTHRU);
              return;
       }
       hostname = username = dbname = passwd = socket = NULL;

       if (!is_real_connect) {
              if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ssssls", &hostname, &hostname_len, &username, &username_len,
                                                               &passwd, &passwd_len, &dbname, &dbname_len, &port, &socket, &socket_len) == FAILURE) {
                     return;
              }

              if (object && instanceof_function(Z_OBJCE_P(object), mysqli_link_class_entry TSRMLS_CC)) {
                     mysqli_resource = ((mysqli_object *) zend_object_store_get_object(object TSRMLS_CC))->ptr;
                     if (mysqli_resource && mysqli_resource->ptr) {
                            mysql = (MY_MYSQL*) mysqli_resource->ptr;
                     }
              }
              if (!mysql) {
                     mysql = (MY_MYSQL *) ecalloc(1, sizeof(MY_MYSQL));
                     self_alloced = 1;
              }
              flags |= CLIENT_MULTI_RESULTS; /* needed for mysql_multi_query() */
       } else {
              /* We have flags too */
              if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|sssslsl", &object, mysqli_link_class_entry,
                                                                      &hostname, &hostname_len, &username, &username_len, &passwd, &passwd_len, &dbname, &dbname_len, &port, &socket, &socket_len,
                                                                      &flags) == FAILURE) {
                     return;
              }

              mysqli_resource = ((mysqli_object *) zend_object_store_get_object(object TSRMLS_CC))->ptr;
              MYSQLI_FETCH_RESOURCE_CONN(mysql, &object, MYSQLI_STATUS_INITIALIZED);

              /* set some required options */
              flags |= CLIENT_MULTI_RESULTS; /* needed for mysql_multi_query() */
              /* remove some insecure options */
              flags &= ~CLIENT_MULTI_STATEMENTS;   /* don't allow multi_queries via connect parameter */
              if (PG(open_basedir) && PG(open_basedir)[0] != '\0') {
                     flags &= ~CLIENT_LOCAL_FILES;
              }
       }

       if (!socket_len || !socket) {
              socket = MyG(default_socket);
       }
       if (!port){
              port = MyG(default_port);
       }
       if (!passwd) {
              passwd = MyG(default_pw);
              passwd_len = strlen(SAFE_STR(passwd));
       }
       if (!username){
              username = MyG(default_user);
       }
       if (!hostname || !hostname_len) {
              hostname = MyG(default_host);
       }

       if (mysql->mysql && mysqli_resource &&
              (mysqli_resource->status > MYSQLI_STATUS_INITIALIZED))
       {
              /* already connected, we should close the connection */
              php_mysqli_close(mysql, MYSQLI_CLOSE_IMPLICIT, mysqli_resource->status TSRMLS_CC);
       }

       if (strlen(SAFE_STR(hostname)) > 2 && !strncasecmp(hostname, "p:", 2)) {
              hostname += 2;
              if (!MyG(allow_persistent)) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Persistent connections are disabled. Downgrading to normal");
              } else {
                     mysql->persistent = persistent = TRUE;

                     hash_len = spprintf(&hash_key, 0, "mysqli_%s_%s%ld%s%s%s", SAFE_STR(hostname), SAFE_STR(socket),
                                                        port, SAFE_STR(username), SAFE_STR(dbname),
                                                        SAFE_STR(passwd));

                     mysql->hash_key = hash_key;

                     /* check if we can reuse exisiting connection ... */
                     if (zend_hash_find(&EG(persistent_list), hash_key, hash_len + 1, (void **)&le) == SUCCESS) {
                            if (Z_TYPE_P(le) == php_le_pmysqli()) {
                                   plist = (mysqli_plist_entry *) le->ptr;

                                   do {
                                          if (zend_ptr_stack_num_elements(&plist->free_links)) {
                                                 mysql->mysql = zend_ptr_stack_pop(&plist->free_links);

                                                 MyG(num_inactive_persistent)--;
                                                 /* reset variables */

#ifndef MYSQLI_NO_CHANGE_USER_ON_PCONNECT
                                                 if (!mysqli_change_user_silent(mysql->mysql, username, passwd, dbname)) {
#else
                                                 if (!mysql_ping(mysql->mysql)) {
#endif
#ifdef MYSQLI_USE_MYSQLND
                                                        mysqlnd_restart_psession(mysql->mysql);
#endif
                                                        MyG(num_active_persistent)++;
                                                        goto end;
                                                 } else {
                                                        mysqli_close(mysql->mysql, MYSQLI_CLOSE_IMPLICIT);
                                                        mysql->mysql = NULL;
                                                 }
                                          }
                                   } while (0);
                            }
                     } else {
                            zend_rsrc_list_entry le;
                            le.type = php_le_pmysqli();
                            le.ptr = plist = calloc(1, sizeof(mysqli_plist_entry));

                            zend_ptr_stack_init_ex(&plist->free_links, 1);
                            zend_hash_update(&EG(persistent_list), hash_key, hash_len + 1, (void *)&le, sizeof(le), NULL);
                     }
              }
       }
       if (MyG(max_links) != -1 && MyG(num_links) >= MyG(max_links)) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too many open links (%ld)", MyG(num_links));
              goto err;
       }

       if (persistent && MyG(max_persistent) != -1 &&
              (MyG(num_active_persistent) + MyG(num_inactive_persistent))>= MyG(max_persistent))
       {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too many open persistent links (%ld)",
                                                        MyG(num_active_persistent) + MyG(num_inactive_persistent));
              goto err;
       }
       if (!mysql->mysql) {
#if !defined(MYSQLI_USE_MYSQLND)
              if (!(mysql->mysql = mysql_init(NULL))) {
#else
              if (!(mysql->mysql = mysqlnd_init(persistent))) {
#endif
                     goto err;
              }
              new_connection = TRUE;
       }

#ifdef HAVE_EMBEDDED_MYSQLI
       if (hostname_len) {
              unsigned int external=1;
              mysql_options(mysql->mysql, MYSQL_OPT_USE_REMOTE_CONNECTION, (char *)&external);
       } else {
              mysql_options(mysql->mysql, MYSQL_OPT_USE_EMBEDDED_CONNECTION, 0);
       }
#endif

#if !defined(MYSQLI_USE_MYSQLND)
       /* BC for prior to bug fix #53425 */
       flags |= CLIENT_MULTI_RESULTS;

       if (mysql_real_connect(mysql->mysql, hostname, username, passwd, dbname, port, socket, flags) == NULL)
#else
       if (mysqlnd_connect(mysql->mysql, hostname, username, passwd, passwd_len, dbname, dbname_len,
                                          port, socket, flags TSRMLS_CC) == NULL)
#endif
       {
              /* Save error messages - for mysqli_connect_error() & mysqli_connect_errno() */
              php_mysqli_set_error(mysql_errno(mysql->mysql), (char *) mysql_error(mysql->mysql) TSRMLS_CC);
              php_mysqli_throw_sql_exception((char *)mysql_sqlstate(mysql->mysql), mysql_errno(mysql->mysql) TSRMLS_CC,
                                                                      "%s", mysql_error(mysql->mysql));
              if (!is_real_connect) {
                     /* free mysql structure */
                     mysqli_close(mysql->mysql, MYSQLI_CLOSE_DISCONNECTED);
                     mysql->mysql = NULL;
              }
              goto err;
       }

       /* clear error */
       php_mysqli_set_error(mysql_errno(mysql->mysql), (char *) mysql_error(mysql->mysql) TSRMLS_CC);

#if !defined(MYSQLI_USE_MYSQLND)
       mysql->mysql->reconnect = MyG(reconnect);

       /* set our own local_infile handler */
       php_set_local_infile_handler_default(mysql);
#endif

       mysql_options(mysql->mysql, MYSQL_OPT_LOCAL_INFILE, (char *)&MyG(allow_local_infile));

end:
       if (!mysqli_resource) {
              mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
              mysqli_resource->ptr = (void *)mysql;
       }
       mysqli_resource->status = MYSQLI_STATUS_VALID;

       /* store persistent connection */
       if (persistent && (new_connection || is_real_connect)) {
              MyG(num_active_persistent)++;
       }

       MyG(num_links)++;

       mysql->multi_query = 0;

       if (!object || !instanceof_function(Z_OBJCE_P(object), mysqli_link_class_entry TSRMLS_CC)) {
              MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_link_class_entry);
       } else {
              ((mysqli_object *) zend_object_store_get_object(object TSRMLS_CC))->ptr = mysqli_resource;
       }
       if (!is_real_connect) {
              return;
       } else {
              RETURN_TRUE;
       }

err:
       if (mysql->hash_key) {
              efree(mysql->hash_key);
              mysql->hash_key = NULL;
              mysql->persistent = FALSE;
       }
       if (!is_real_connect && self_alloced) {
              efree(mysql);
       }
       RETVAL_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void php_clear_mysql ( MY_MYSQL )

Definition at line 187 of file mysqli.c.

                                      {
       if (mysql->hash_key) {
              efree(mysql->hash_key);
              mysql->hash_key = NULL;
       }
       if (mysql->li_read) {
              zval_ptr_dtor(&(mysql->li_read));
              mysql->li_read = NULL;
       }
}

Here is the caller graph for this function:

void php_clear_stmt_bind ( MY_STMT *stmt  TSRMLS_DC)

Definition at line 159 of file mysqli.c.

{
       if (stmt->stmt) {
              if (mysqli_stmt_close(stmt->stmt, TRUE)) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error occured while closing statement");
                     return;
              }
       }

       /*
         mysqlnd keeps track of the binding and has freed its
         structures in stmt_close() above
       */
#ifndef MYSQLI_USE_MYSQLND
       /* Clean param bind */
       php_free_stmt_bind_buffer(stmt->param, FETCH_SIMPLE);
       /* Clean output bind */
       php_free_stmt_bind_buffer(stmt->result, FETCH_RESULT);
#endif

       if (stmt->query) {
              efree(stmt->query);
       }
       efree(stmt);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void php_clear_warnings ( MYSQLI_WARNING *  w)

Definition at line 40 of file mysqli_warning.c.

{
       MYSQLI_WARNING *n;

       while (w) {
              n = w;
              zval_dtor(&(w->reason));
              zval_dtor(&(w->sqlstate));
              w = w->next;
              efree(n);
       }
}

Here is the caller graph for this function:

void php_free_stmt_bind_buffer ( BIND_BUFFER  bbuf,
int  type 
)

Definition at line 117 of file mysqli.c.

{
       unsigned int i;

       if (!bbuf.var_cnt) {
              return;
       }

       for (i=0; i < bbuf.var_cnt; i++) {

              /* free temporary bind buffer */
              if (type == FETCH_RESULT && bbuf.buf[i].val) {
                     efree(bbuf.buf[i].val);
              }

              if (bbuf.vars[i]) {
                     zval_ptr_dtor(&bbuf.vars[i]);
              }
       }

       if (bbuf.vars) {
              efree(bbuf.vars);
       }

       /*
         Don't free bbuf.is_null for FETCH_RESULT since we have allocated
         is_null and buf in one block so we free only buf, which is the beginning
         of the block. When FETCH_SIMPLE then buf wasn't allocated together with
         buf and we have to free it.
       */
       if (type == FETCH_RESULT) {
              efree(bbuf.buf);
       } else if (type == FETCH_SIMPLE){
              efree(bbuf.is_null);
       }

       bbuf.var_cnt = 0;
}

Here is the caller graph for this function:

MYSQLI_WARNING* php_get_warnings ( MYSQL *mysql  TSRMLS_DC)

Definition at line 76 of file mysqli_warning.c.

{
       MYSQLI_WARNING *w, *first = NULL, *prev = NULL;
       MYSQL_RES            *result;
       MYSQL_ROW            row;

       if (mysql_real_query(mysql, "SHOW WARNINGS", 13)) {
              return NULL;
       }

       result = mysql_store_result(mysql);

       while ((row = mysql_fetch_row(result))) {
              w = php_new_warning(row[2], atoi(row[1]) TSRMLS_CC);
              if (!first) {
                     first = w;
              }
              if (prev) {
                     prev->next = w;
              }
              prev = w;
       }
       mysql_free_result(result);
       return first;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int php_le_pmysqli ( void  )

Definition at line 110 of file mysqli.c.

{
       return le_pmysqli;
}

Here is the caller 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:

void php_mysqli_dtor_p_elements ( void *  data)

Definition at line 91 of file mysqli.c.

{
       MYSQL *mysql = (MYSQL *) data;
       TSRMLS_FETCH();
       mysqli_close(mysql, MYSQLI_CLOSE_IMPLICIT);
}

Here is the caller graph for this function:

Definition at line 483 of file mysqli.c.

{
       zend_object_value retval;
       mysqli_object *intern;
       zval *tmp;
       zend_class_entry *mysqli_base_class;
       zend_objects_free_object_storage_t free_storage;

       intern = emalloc(sizeof(mysqli_object));
       memset(intern, 0, sizeof(mysqli_object));
       intern->ptr = NULL;
       intern->prop_handler = NULL;

       mysqli_base_class = class_type;
       while (mysqli_base_class->type != ZEND_INTERNAL_CLASS &&
                 mysqli_base_class->parent != NULL) {
              mysqli_base_class = mysqli_base_class->parent;
       }
       zend_hash_find(&classes, mysqli_base_class->name, mysqli_base_class->name_length + 1,
                                   (void **) &intern->prop_handler);

       zend_object_std_init(&intern->zo, class_type TSRMLS_CC);
       zend_hash_copy(intern->zo.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref,
                                   (void *) &tmp, sizeof(zval *));

       /* link object */
       if (instanceof_function(class_type, mysqli_link_class_entry TSRMLS_CC)) {
              free_storage = mysqli_link_free_storage;
       } else if (instanceof_function(class_type, mysqli_driver_class_entry TSRMLS_CC)) { /* driver object */
              free_storage = mysqli_driver_free_storage;
       } else if (instanceof_function(class_type, mysqli_stmt_class_entry TSRMLS_CC)) { /* stmt object */
              free_storage = mysqli_stmt_free_storage;
       } else if (instanceof_function(class_type, mysqli_result_class_entry TSRMLS_CC)) { /* result object */
              free_storage = mysqli_result_free_storage;
       } else if (instanceof_function(class_type, mysqli_warning_class_entry TSRMLS_CC)) { /* warning object */
              free_storage = mysqli_warning_free_storage;
       } else {
              free_storage = mysqli_objects_free_storage;
       }

       retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, free_storage, NULL TSRMLS_CC);
       retval.handlers = &mysqli_object_handlers;

       return retval;
}

Here is the call graph for this function:

void php_mysqli_fetch_into_hash ( INTERNAL_FUNCTION_PARAMETERS  ,
int  override_flag,
int  into_object 
)

Definition at line 1088 of file mysqli.c.

{
       MYSQL_RES            *result;
       zval                 *mysql_result;
       long                 fetchtype;
       zval                 *ctor_params = NULL;
       zend_class_entry *ce = NULL;
#if !defined(MYSQLI_USE_MYSQLND)
       unsigned int  i;
       MYSQL_FIELD          *fields;
       MYSQL_ROW            row;
       unsigned long *field_len;
       zend_bool magic_quotes_warning_sent = FALSE;
#endif

       if (into_object) {
              char *class_name;
              int class_name_len;

              if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|sz", &mysql_result, mysqli_result_class_entry, &class_name, &class_name_len, &ctor_params) == FAILURE) {
                     return;
              }
              if (ZEND_NUM_ARGS() < (getThis() ? 1 : 2)) {
                     ce = zend_standard_class_def;
              } else {
                     ce = zend_fetch_class(class_name, class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
              }
              if (!ce) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not find class '%s'", class_name);
                     return;
              }
              fetchtype = MYSQLI_ASSOC;
       } else {
              if (override_flags) {
                     if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
                            return;
                     }
                     fetchtype = override_flags;
              } else {
                     fetchtype = MYSQLI_BOTH;
                     if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|l", &mysql_result, mysqli_result_class_entry, &fetchtype) == FAILURE) {
                            return;
                     }
              }
       }
       MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);

       if (fetchtype < MYSQLI_ASSOC || fetchtype > MYSQLI_BOTH) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "The result type should be either MYSQLI_NUM, MYSQLI_ASSOC or MYSQLI_BOTH");
              RETURN_FALSE;
       }

#if !defined(MYSQLI_USE_MYSQLND)
       if (!(row = mysql_fetch_row(result))) {
              RETURN_NULL();
       }

       if (fetchtype & MYSQLI_ASSOC) {
              fields = mysql_fetch_fields(result);
       }

       array_init(return_value);
       field_len = mysql_fetch_lengths(result);

       for (i = 0; i < mysql_num_fields(result); i++) {
              if (row[i]) {
                     zval *res;

                     MAKE_STD_ZVAL(res);

#if MYSQL_VERSION_ID > 50002
                     if (mysql_fetch_field_direct(result, i)->type == MYSQL_TYPE_BIT) {
                            my_ulonglong llval;
                            char tmp[22];
                            switch (field_len[i]) {
                                   case 8:llval = (my_ulonglong)  bit_uint8korr(row[i]);break;
                                   case 7:llval = (my_ulonglong)  bit_uint7korr(row[i]);break;
                                   case 6:llval = (my_ulonglong)  bit_uint6korr(row[i]);break;
                                   case 5:llval = (my_ulonglong)  bit_uint5korr(row[i]);break;
                                   case 4:llval = (my_ulonglong)  bit_uint4korr(row[i]);break;
                                   case 3:llval = (my_ulonglong)  bit_uint3korr(row[i]);break;
                                   case 2:llval = (my_ulonglong)  bit_uint2korr(row[i]);break;
                                   case 1:llval = (my_ulonglong)  uint1korr(row[i]);break;
                            }
                            /* 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), (mysql_fetch_field_direct(result, i)->flags & UNSIGNED_FLAG)? MYSQLI_LLU_SPEC : MYSQLI_LL_SPEC, llval);
                            ZVAL_STRING(res, tmp, 1);
                     } else
#endif
                     {

                            /* check if we need magic quotes */
                            if (PG(magic_quotes_runtime)) {
                                   if (magic_quotes_warning_sent == FALSE) {
                                          magic_quotes_warning_sent = TRUE;
                                          php_error_docref(NULL TSRMLS_CC, E_WARNING, "magic_quotes_runtime are deprecated since PHP 5.3");
                                   }
                                   Z_TYPE_P(res) = IS_STRING;
                                   Z_STRVAL_P(res) = php_addslashes(row[i], field_len[i], &Z_STRLEN_P(res), 0 TSRMLS_CC);
                            } else {
                                   ZVAL_STRINGL(res, row[i], field_len[i], 1);
                            }
                     }

                     if (fetchtype & MYSQLI_NUM) {
                            add_index_zval(return_value, i, res);
                     }
                     if (fetchtype & MYSQLI_ASSOC) {
                            if (fetchtype & MYSQLI_NUM) {
                                   Z_ADDREF_P(res);
                            }
                            add_assoc_zval(return_value, fields[i].name, res);
                     }
              } else {
                     if (fetchtype & MYSQLI_NUM) {
                            add_index_null(return_value, i);
                     }
                     if (fetchtype & MYSQLI_ASSOC) {
                            add_assoc_null(return_value, fields[i].name);
                     }
              }
       }
#else
       if (PG(magic_quotes_runtime)) {
              HashPosition pos_values;
              zval **entry_values;
              zval new_return_value;
              char * string_key;
              uint   string_key_len;
              ulong  num_key;

              mysqlnd_fetch_into(result, ((fetchtype & MYSQLI_NUM)? MYSQLND_FETCH_NUM:0) | ((fetchtype & MYSQLI_ASSOC)? MYSQLND_FETCH_ASSOC:0), &new_return_value, MYSQLND_MYSQLI);
              if (Z_TYPE(new_return_value) == IS_ARRAY) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "magic_quotes_runtime are deprecated since PHP 5.3");
                     array_init(return_value);
                     zend_hash_internal_pointer_reset_ex(Z_ARRVAL(new_return_value), &pos_values);
                     while (zend_hash_get_current_data_ex(Z_ARRVAL(new_return_value), (void **)&entry_values, &pos_values) == SUCCESS) {
                            if (Z_TYPE_PP(entry_values) == IS_STRING) {
                                   int new_str_len;
                                   char * new_str = php_addslashes(Z_STRVAL_PP(entry_values), Z_STRLEN_PP(entry_values), &new_str_len, 0 TSRMLS_CC);
                                   switch (zend_hash_get_current_key_ex(Z_ARRVAL(new_return_value), &string_key, &string_key_len, &num_key, 0, &pos_values)) {
                                          case HASH_KEY_IS_LONG:
                                                 add_index_stringl(return_value, num_key, new_str, new_str_len, 0);
                                                 break;
                                          case HASH_KEY_IS_STRING:
                                                 add_assoc_stringl_ex(return_value, string_key, string_key_len, new_str, new_str_len, 0);
                                                 break;
                                   }
                            } else {
                                   zval_add_ref(entry_values);
                                   switch (zend_hash_get_current_key_ex(Z_ARRVAL(new_return_value), &string_key, &string_key_len, &num_key, 0, &pos_values)) {
                                          case HASH_KEY_IS_LONG:
                                                 add_index_zval(return_value, num_key, *entry_values);
                                                 break;
                                          case HASH_KEY_IS_STRING:
                                                 add_assoc_zval_ex(return_value, string_key, string_key_len, *entry_values);
                                                 break;
                                   }
                            }
                            zend_hash_move_forward_ex(Z_ARRVAL(new_return_value), &pos_values);
                     }
              } else {
                     RETVAL_NULL();
              }
              zval_dtor(&new_return_value);
       } else {
              mysqlnd_fetch_into(result, ((fetchtype & MYSQLI_NUM)? MYSQLND_FETCH_NUM:0) | ((fetchtype & MYSQLI_ASSOC)? MYSQLND_FETCH_ASSOC:0), return_value, MYSQLND_MYSQLI);
       }

#endif

       if (into_object && Z_TYPE_P(return_value) != IS_NULL) {
              zval dataset = *return_value;
              zend_fcall_info fci;
              zend_fcall_info_cache fcc;
              zval *retval_ptr;

              object_and_properties_init(return_value, ce, NULL);
              zend_merge_properties(return_value, Z_ARRVAL(dataset), 1 TSRMLS_CC);

              if (ce->constructor) {
                     fci.size = sizeof(fci);
                     fci.function_table = &ce->function_table;
                     fci.function_name = NULL;
                     fci.symbol_table = NULL;
                     fci.object_ptr = return_value;
                     fci.retval_ptr_ptr = &retval_ptr;
                     if (ctor_params && Z_TYPE_P(ctor_params) != IS_NULL) {
                            if (Z_TYPE_P(ctor_params) == IS_ARRAY) {
                                   HashTable *params_ht = Z_ARRVAL_P(ctor_params);
                                   Bucket *p;

                                   fci.param_count = 0;
                                   fci.params = safe_emalloc(sizeof(zval*), params_ht->nNumOfElements, 0);
                                   p = params_ht->pListHead;
                                   while (p != NULL) {
                                          fci.params[fci.param_count++] = (zval**)p->pData;
                                          p = p->pListNext;
                                   }
                            } else {
                                   /* Two problems why we throw exceptions here: PHP is typeless
                                    * and hence passing one argument that's not an array could be
                                    * by mistake and the other way round is possible, too. The
                                    * single value is an array. Also we'd have to make that one
                                    * argument passed by reference.
                                    */
                                   zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Parameter ctor_params must be an array", 0 TSRMLS_CC);
                                   return;
                            }
                     } else {
                            fci.param_count = 0;
                            fci.params = NULL;
                     }
                     fci.no_separation = 1;

                     fcc.initialized = 1;
                     fcc.function_handler = ce->constructor;
                     fcc.calling_scope = EG(scope);
                     fcc.called_scope = Z_OBJCE_P(return_value);
                     fcc.object_ptr = return_value;

                     if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) {
                            zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Could not execute %s::%s()", ce->name, ce->constructor->common.function_name);
                     } else {
                            if (retval_ptr) {
                                   zval_ptr_dtor(&retval_ptr);
                            }
                     }
                     if (fci.params) {
                            efree(fci.params);
                     }
              } else if (ctor_params) {
                     zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Class %s does not have a constructor hence you cannot use ctor_params", ce->name);
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Here is the caller graph for this function:

void php_mysqli_report_error ( const char *  sqlstate,
int  errorno,
const char *error  TSRMLS_DC 
)

Definition at line 50 of file mysqli_report.c.

Here is the call graph for this function:

void php_mysqli_report_index ( const char *  query,
unsigned int status  TSRMLS_DC 
)

Definition at line 57 of file mysqli_report.c.

                                                                               {
       char index[15];

       if (status & SERVER_QUERY_NO_GOOD_INDEX_USED) {
              strcpy(index, "Bad index");
       } else if (status & SERVER_QUERY_NO_INDEX_USED) {
              strcpy(index, "No index");
       } else {
              return;
       }
       php_mysqli_throw_sql_exception("00000", 0 TSRMLS_CC, "%s used in query/prepared statement %s", index, query);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void php_mysqli_throw_sql_exception ( char *  sqlstate,
int errorno  TSRMLS_DC,
char *  format,
  ... 
)

Definition at line 39 of file mysqli_exception.c.

{
       zval   *sql_ex;
       va_list arg;
       char   *message;

       va_start(arg, format);
       vspprintf(&message, 0, format, arg);
       va_end(arg);;

       if (!(MyG(report_mode) & MYSQLI_REPORT_STRICT)) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "(%s/%d): %s", sqlstate, errorno, message);
              efree(message);
              return;
       }

       MAKE_STD_ZVAL(sql_ex);
       object_init_ex(sql_ex, mysqli_exception_class_entry);

       if (message) {
              zend_update_property_string(mysqli_exception_class_entry, sql_ex, "message", sizeof("message") - 1,
                                                               message TSRMLS_CC);
       }

       if (sqlstate) {
              zend_update_property_string(mysqli_exception_class_entry, sql_ex, "sqlstate", sizeof("sqlstate") - 1,
                                                               sqlstate TSRMLS_CC);
       } else {
              zend_update_property_string(mysqli_exception_class_entry, sql_ex, "sqlstate", sizeof("sqlstate") - 1,
                                                               "00000" TSRMLS_CC);
       }

       efree(message);
       zend_update_property_long(mysqli_exception_class_entry, sql_ex, "code", sizeof("code") - 1, errorno TSRMLS_CC);

       zend_throw_exception_object(sql_ex TSRMLS_CC);
}

Definition at line 1529 of file mysqli.c.

                                                           {
       /* register internal callback functions */
       mysql_set_local_infile_handler(mysql->mysql, &php_local_infile_init, &php_local_infile_read,
                            &php_local_infile_end, &php_local_infile_error, (void *)mysql);
       if (mysql->li_read) {
              zval_ptr_dtor(&mysql->li_read);
              mysql->li_read = NULL;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 168 of file mysqli_driver.c.

Definition at line 143 of file mysqli_driver.c.

Definition at line 154 of file mysqli_driver.c.

Definition at line 34 of file mysqli_exception.c.

Definition at line 336 of file mysqli_fe.c.

Definition at line 479 of file mysqli_fe.c.

Definition at line 348 of file mysqli_prop.c.

Definition at line 371 of file mysqli_prop.c.

Definition at line 543 of file mysqli_fe.c.

Definition at line 394 of file mysqli_prop.c.

Definition at line 403 of file mysqli_prop.c.

Definition at line 568 of file mysqli_fe.c.

Definition at line 412 of file mysqli_prop.c.

Definition at line 426 of file mysqli_prop.c.

Definition at line 316 of file mysqli_warning.c.

Definition at line 324 of file mysqli_warning.c.

Definition at line 333 of file mysqli_warning.c.