2003-02-12 08:45:53 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2003-02-22 15:31:01 +08:00
|
|
|
| PHP Version 5 |
|
2003-02-12 08:45:53 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2004-01-08 16:18:22 +08:00
|
|
|
| Copyright (c) 1997-2004 The PHP Group |
|
2003-02-12 08:45:53 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2003-06-11 04:04:29 +08:00
|
|
|
| This source file is subject to version 3.0 of the PHP license, |
|
2003-02-12 08:45:53 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-11 04:04:29 +08:00
|
|
|
| available through the world-wide-web at the following url: |
|
|
|
|
| http://www.php.net/license/3_0.txt. |
|
2003-02-12 08:45:53 +08:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Author: Georg Richter <georg@php.net> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include "php.h"
|
|
|
|
#include "php_ini.h"
|
|
|
|
#include "ext/standard/info.h"
|
2003-02-15 00:49:09 +08:00
|
|
|
#include "ext/standard/php_string.h"
|
2003-02-12 08:45:53 +08:00
|
|
|
#include "php_mysqli.h"
|
2004-02-12 18:43:27 +08:00
|
|
|
#include "zend_exceptions.h"
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
#define MYSQLI_STORE_RESULT 0
|
|
|
|
#define MYSQLI_USE_RESULT 1
|
|
|
|
|
|
|
|
ZEND_DECLARE_MODULE_GLOBALS(mysqli)
|
|
|
|
static zend_object_handlers mysqli_object_handlers;
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
static HashTable classes;
|
2005-01-07 22:59:59 +08:00
|
|
|
static HashTable mysqli_driver_properties;
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
static HashTable mysqli_link_properties;
|
|
|
|
static HashTable mysqli_result_properties;
|
|
|
|
static HashTable mysqli_stmt_properties;
|
2005-01-07 22:59:59 +08:00
|
|
|
static HashTable mysqli_warning_properties;
|
|
|
|
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
extern void php_mysqli_connect(INTERNAL_FUNCTION_PARAMETERS);
|
|
|
|
|
|
|
|
typedef int (*mysqli_read_t)(mysqli_object *obj, zval **retval TSRMLS_DC);
|
2003-11-24 19:31:26 +08:00
|
|
|
typedef int (*mysqli_write_t)(mysqli_object *obj, zval *newval TSRMLS_DC);
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
|
|
|
|
typedef struct _mysqli_prop_handler {
|
|
|
|
mysqli_read_t read_func;
|
|
|
|
mysqli_write_t write_func;
|
|
|
|
} mysqli_prop_handler;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-07-15 18:37:19 +08:00
|
|
|
/* {{{ php_free_stmt_bind_buffer */
|
|
|
|
void php_free_stmt_bind_buffer(BIND_BUFFER bbuf, int type)
|
2003-02-15 00:49:09 +08:00
|
|
|
{
|
|
|
|
unsigned int i;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-07-15 18:37:19 +08:00
|
|
|
if (!bbuf.var_cnt) {
|
|
|
|
return;
|
2003-02-22 15:31:01 +08:00
|
|
|
}
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-07-15 18:37:19 +08:00
|
|
|
if (bbuf.is_null) {
|
|
|
|
efree(bbuf.is_null);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i < bbuf.var_cnt; i++) {
|
2004-03-17 05:43:25 +08:00
|
|
|
|
|
|
|
/* free temporary bind buffer */
|
2003-07-15 18:37:19 +08:00
|
|
|
if (type == FETCH_RESULT) {
|
2004-03-18 21:03:17 +08:00
|
|
|
efree(bbuf.buf[i].val);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
2004-03-17 05:43:25 +08:00
|
|
|
|
2003-07-15 18:37:19 +08:00
|
|
|
if (bbuf.vars[i]) {
|
2004-02-15 20:58:19 +08:00
|
|
|
zval_ptr_dtor(&bbuf.vars[i]);
|
2003-07-15 18:37:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bbuf.vars) {
|
|
|
|
efree(bbuf.vars);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == FETCH_RESULT) {
|
|
|
|
efree(bbuf.buf);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
2003-07-15 18:37:19 +08:00
|
|
|
bbuf.var_cnt = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ php_clear_stmt_bind */
|
2004-06-06 02:31:56 +08:00
|
|
|
void php_clear_stmt_bind(MY_STMT *stmt)
|
2003-07-15 18:37:19 +08:00
|
|
|
{
|
|
|
|
if (stmt->stmt) {
|
|
|
|
mysql_stmt_close(stmt->stmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
php_free_stmt_bind_buffer(stmt->param, FETCH_SIMPLE);
|
|
|
|
php_free_stmt_bind_buffer(stmt->result, FETCH_RESULT);
|
|
|
|
|
2004-03-17 05:43:25 +08:00
|
|
|
if (stmt->query) {
|
|
|
|
efree(stmt->query);
|
|
|
|
}
|
2003-02-12 08:45:53 +08:00
|
|
|
efree(stmt);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2004-06-06 02:31:56 +08:00
|
|
|
/* {{{ php_clear_mysql */
|
|
|
|
void php_clear_mysql(MY_MYSQL *mysql) {
|
2004-08-25 21:57:35 +08:00
|
|
|
if (mysql->li_read) {
|
|
|
|
efree(Z_STRVAL_P(mysql->li_read));
|
|
|
|
FREE_ZVAL(mysql->li_read);
|
|
|
|
mysql->li_read = NULL;
|
2004-06-06 02:31:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2004-02-04 19:14:47 +08:00
|
|
|
/* {{{ mysqli_objects_free_storage
|
2003-02-12 08:45:53 +08:00
|
|
|
*/
|
2004-02-07 21:45:44 +08:00
|
|
|
static void mysqli_objects_free_storage(zend_object *object TSRMLS_DC)
|
2003-02-12 08:45:53 +08:00
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
mysqli_object *intern = (mysqli_object *)object;
|
|
|
|
MYSQLI_RESOURCE *my_res = (MYSQLI_RESOURCE *)intern->ptr;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
zend_hash_destroy(intern->zo.properties);
|
|
|
|
FREE_HASHTABLE(intern->zo.properties);
|
|
|
|
|
2003-02-12 08:45:53 +08:00
|
|
|
/* link object */
|
2004-07-06 03:36:10 +08:00
|
|
|
if (instanceof_function(intern->zo.ce, mysqli_link_class_entry TSRMLS_CC)) {
|
2003-03-09 07:33:12 +08:00
|
|
|
if (my_res && my_res->ptr) {
|
2004-06-06 02:31:56 +08:00
|
|
|
MY_MYSQL *mysql = (MY_MYSQL *)my_res->ptr;
|
|
|
|
|
|
|
|
mysql_close(mysql->mysql);
|
|
|
|
|
|
|
|
php_clear_mysql(mysql);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
2003-02-15 00:49:09 +08:00
|
|
|
} else if (intern->zo.ce == mysqli_stmt_class_entry) { /* stmt object */
|
2003-03-09 07:33:12 +08:00
|
|
|
if (my_res && my_res->ptr) {
|
2004-06-06 02:31:56 +08:00
|
|
|
php_clear_stmt_bind((MY_STMT *)my_res->ptr);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
2003-02-15 00:49:09 +08:00
|
|
|
} else if (intern->zo.ce == mysqli_result_class_entry) { /* result object */
|
2003-03-09 07:33:12 +08:00
|
|
|
if (my_res && my_res->ptr) {
|
|
|
|
mysql_free_result(my_res->ptr);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
2005-01-07 22:59:59 +08:00
|
|
|
} else if (intern->zo.ce == mysqli_warning_class_entry) { /* warning object */
|
|
|
|
if (my_res && my_res->ptr) {
|
|
|
|
php_clear_warnings((MYSQLI_WARNING *)my_res->ptr);
|
|
|
|
}
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
2003-03-09 07:33:12 +08:00
|
|
|
my_efree(my_res);
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
efree(object);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
/* {{{ mysqli_read_na */
|
|
|
|
static int mysqli_read_na(mysqli_object *obj, zval **retval TSRMLS_DC)
|
|
|
|
{
|
|
|
|
*retval = NULL;
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot read property");
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ mysqli_write_na */
|
2003-11-24 19:31:26 +08:00
|
|
|
static int mysqli_write_na(mysqli_object *obj, zval *newval TSRMLS_DC)
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
{
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot write property");
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ mysqli_read_property */
|
2004-03-22 02:28:38 +08:00
|
|
|
zval *mysqli_read_property(zval *object, zval *member, int type TSRMLS_DC)
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
{
|
|
|
|
zval tmp_member;
|
|
|
|
zval *retval;
|
|
|
|
mysqli_object *obj;
|
|
|
|
mysqli_prop_handler *hnd;
|
|
|
|
zend_object_handlers *std_hnd;
|
|
|
|
int ret;
|
|
|
|
|
2003-12-31 16:34:02 +08:00
|
|
|
ret = FAILURE;
|
|
|
|
obj = (mysqli_object *)zend_objects_get_address(object TSRMLS_CC);
|
|
|
|
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
if (member->type != IS_STRING) {
|
|
|
|
tmp_member = *member;
|
|
|
|
zval_copy_ctor(&tmp_member);
|
|
|
|
convert_to_string(&tmp_member);
|
|
|
|
member = &tmp_member;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj->prop_handler != NULL) {
|
|
|
|
ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
|
|
|
|
}
|
2004-12-04 16:16:04 +08:00
|
|
|
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
if (ret == SUCCESS) {
|
2004-08-14 00:25:29 +08:00
|
|
|
|
|
|
|
/* check if mysqli object is still valid */
|
|
|
|
if (!strcmp(obj->zo.ce->name, "mysqli")) {
|
|
|
|
if (!obj->ptr ||
|
|
|
|
!((MYSQL *)((MY_MYSQL *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr)->mysql)->thread_id) {
|
|
|
|
retval = EG(uninitialized_zval_ptr);
|
|
|
|
return(retval);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
/* check if stmt object is still valid */
|
|
|
|
if (!strcmp(obj->zo.ce->name, "mysqli_stmt")) {
|
|
|
|
if (!obj->ptr ||
|
|
|
|
!((MYSQL_STMT *)((MY_STMT *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr)->stmt)->mysql) {
|
|
|
|
retval = EG(uninitialized_zval_ptr);
|
|
|
|
return(retval);
|
|
|
|
}
|
2004-08-04 20:28:09 +08:00
|
|
|
}
|
|
|
|
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
ret = hnd->read_func(obj, &retval TSRMLS_CC);
|
|
|
|
if (ret == SUCCESS) {
|
|
|
|
/* ensure we're creating a temporary variable */
|
|
|
|
retval->refcount = 0;
|
|
|
|
} else {
|
|
|
|
retval = EG(uninitialized_zval_ptr);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
std_hnd = zend_get_std_object_handlers();
|
2004-03-22 02:28:38 +08:00
|
|
|
retval = std_hnd->read_property(object, member, type TSRMLS_CC);
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (member == &tmp_member) {
|
|
|
|
zval_dtor(member);
|
|
|
|
}
|
|
|
|
return(retval);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-12-31 16:34:02 +08:00
|
|
|
/* {{{ mysqli_write_property */
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
void mysqli_write_property(zval *object, zval *member, zval *value TSRMLS_DC)
|
|
|
|
{
|
2003-11-24 19:31:26 +08:00
|
|
|
zval tmp_member;
|
|
|
|
mysqli_object *obj;
|
|
|
|
mysqli_prop_handler *hnd;
|
|
|
|
zend_object_handlers *std_hnd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (member->type != IS_STRING) {
|
|
|
|
tmp_member = *member;
|
|
|
|
zval_copy_ctor(&tmp_member);
|
|
|
|
convert_to_string(&tmp_member);
|
|
|
|
member = &tmp_member;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = FAILURE;
|
|
|
|
obj = (mysqli_object *)zend_objects_get_address(object TSRMLS_CC);
|
|
|
|
|
|
|
|
if (obj->prop_handler != NULL) {
|
|
|
|
ret = zend_hash_find((HashTable *)obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
|
|
|
|
}
|
|
|
|
if (ret == SUCCESS) {
|
|
|
|
hnd->write_func(obj, value TSRMLS_CC);
|
|
|
|
if (! PZVAL_IS_REF(value) && value->refcount == 0) {
|
|
|
|
value->refcount++;
|
|
|
|
zval_ptr_dtor(&value);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
std_hnd = zend_get_std_object_handlers();
|
|
|
|
std_hnd->write_property(object, member, value TSRMLS_CC);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (member == &tmp_member) {
|
|
|
|
zval_dtor(member);
|
|
|
|
}
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-12-13 08:28:21 +08:00
|
|
|
/* {{{ void mysqli_add_property(HashTable *h, char *pname, mysqli_read_t r_func, mysqli_write_t w_func TSRMLS_DC) */
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
void mysqli_add_property(HashTable *h, char *pname, mysqli_read_t r_func, mysqli_write_t w_func TSRMLS_DC) {
|
|
|
|
mysqli_prop_handler p;
|
|
|
|
|
|
|
|
p.read_func = (r_func) ? r_func : mysqli_read_na;
|
|
|
|
p.write_func = (w_func) ? w_func : mysqli_write_na;
|
|
|
|
|
|
|
|
zend_hash_add(h, pname, strlen(pname) + 1, &p, sizeof(mysqli_prop_handler), NULL);
|
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
/* }}} */
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
|
2004-06-24 00:47:25 +08:00
|
|
|
static union _zend_function *php_mysqli_constructor_get(zval *object TSRMLS_DC)
|
|
|
|
{
|
|
|
|
mysqli_object *obj = (mysqli_object *)zend_objects_get_address(object TSRMLS_CC);
|
|
|
|
|
2004-12-26 21:16:40 +08:00
|
|
|
if (obj->zo.ce != mysqli_link_class_entry && obj->zo.ce != mysqli_stmt_class_entry &&
|
2005-01-07 22:59:59 +08:00
|
|
|
obj->zo.ce != mysqli_result_class_entry && obj->zo.ce != mysqli_driver_class_entry &&
|
|
|
|
obj->zo.ce != mysqli_warning_class_entry) {
|
2004-06-24 00:47:25 +08:00
|
|
|
return obj->zo.ce->constructor;
|
|
|
|
} else {
|
|
|
|
static zend_internal_function f;
|
|
|
|
|
2004-12-26 21:16:40 +08:00
|
|
|
f.function_name = obj->zo.ce->name;
|
|
|
|
f.scope = obj->zo.ce;
|
2004-06-24 00:47:25 +08:00
|
|
|
f.arg_info = NULL;
|
|
|
|
f.num_args = 0;
|
|
|
|
f.fn_flags = 0;
|
|
|
|
|
|
|
|
f.type = ZEND_INTERNAL_FUNCTION;
|
2004-12-26 21:16:40 +08:00
|
|
|
if (obj->zo.ce == mysqli_link_class_entry) {
|
|
|
|
f.handler = ZEND_FN(mysqli_connect);
|
|
|
|
} else if (obj->zo.ce == mysqli_stmt_class_entry) {
|
|
|
|
f.handler = ZEND_FN(mysqli_stmt_construct);
|
|
|
|
} else if (obj->zo.ce == mysqli_result_class_entry) {
|
|
|
|
f.handler = ZEND_FN(mysqli_result_construct);
|
2005-01-07 22:59:59 +08:00
|
|
|
} else if (obj->zo.ce == mysqli_driver_class_entry) {
|
|
|
|
f.handler = ZEND_FN(mysqli_driver_construct);
|
|
|
|
} else if (obj->zo.ce == mysqli_warning_class_entry) {
|
|
|
|
f.handler = ZEND_FN(mysqli_driver_construct);
|
2004-12-26 21:16:40 +08:00
|
|
|
}
|
2004-06-24 00:47:25 +08:00
|
|
|
|
|
|
|
return (union _zend_function*)&f;
|
|
|
|
}
|
|
|
|
}
|
2004-12-26 21:16:40 +08:00
|
|
|
|
2003-02-12 08:45:53 +08:00
|
|
|
/* {{{ mysqli_objects_new
|
|
|
|
*/
|
|
|
|
PHP_MYSQLI_EXPORT(zend_object_value) mysqli_objects_new(zend_class_entry *class_type TSRMLS_DC)
|
|
|
|
{
|
|
|
|
zend_object_value retval;
|
|
|
|
mysqli_object *intern;
|
|
|
|
zval *tmp;
|
2004-12-03 15:56:19 +08:00
|
|
|
zend_class_entry *mysqli_base_class;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
intern = emalloc(sizeof(mysqli_object));
|
2004-06-06 02:31:56 +08:00
|
|
|
memset(intern, 0, sizeof(mysqli_object));
|
2003-02-12 08:45:53 +08:00
|
|
|
intern->zo.ce = class_type;
|
|
|
|
intern->zo.in_get = 0;
|
|
|
|
intern->zo.in_set = 0;
|
2003-03-22 02:08:59 +08:00
|
|
|
intern->ptr = NULL;
|
2003-12-31 16:34:02 +08:00
|
|
|
intern->valid = 0;
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
intern->prop_handler = NULL;
|
2004-12-03 15:56:19 +08:00
|
|
|
|
|
|
|
mysqli_base_class = class_type;
|
|
|
|
while (mysqli_base_class->type != ZEND_INTERNAL_CLASS && mysqli_base_class->parent != NULL)
|
2004-06-06 02:31:56 +08:00
|
|
|
{
|
2004-12-03 15:56:19 +08:00
|
|
|
mysqli_base_class = mysqli_base_class->parent;
|
2004-06-06 02:31:56 +08:00
|
|
|
}
|
2004-12-03 15:56:19 +08:00
|
|
|
zend_hash_find(&classes, mysqli_base_class->name, mysqli_base_class->name_length + 1,
|
|
|
|
(void **) &intern->prop_handler);
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
ALLOC_HASHTABLE(intern->zo.properties);
|
|
|
|
zend_hash_init(intern->zo.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
|
2003-12-13 08:28:21 +08:00
|
|
|
zend_hash_copy(intern->zo.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref,
|
|
|
|
(void *) &tmp, sizeof(zval *));
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2004-06-06 02:31:56 +08:00
|
|
|
retval.handle = zend_objects_store_put(intern, NULL, mysqli_objects_free_storage, NULL TSRMLS_CC);
|
2003-02-12 08:45:53 +08:00
|
|
|
retval.handlers = &mysqli_object_handlers;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ mysqli_module_entry
|
|
|
|
*/
|
|
|
|
zend_module_entry mysqli_module_entry = {
|
|
|
|
#if ZEND_MODULE_API_NO >= 20010901
|
|
|
|
STANDARD_MODULE_HEADER,
|
|
|
|
#endif
|
|
|
|
"mysqli",
|
|
|
|
mysqli_functions,
|
|
|
|
PHP_MINIT(mysqli),
|
|
|
|
PHP_MSHUTDOWN(mysqli),
|
|
|
|
PHP_RINIT(mysqli), /* Replace with NULL if there's nothing to do at request start */
|
|
|
|
PHP_RSHUTDOWN(mysqli), /* Replace with NULL if there's nothing to do at request end */
|
|
|
|
PHP_MINFO(mysqli),
|
|
|
|
#if ZEND_MODULE_API_NO >= 20010901
|
|
|
|
"0.1", /* Replace with version number for your extension */
|
|
|
|
#endif
|
|
|
|
STANDARD_MODULE_PROPERTIES
|
|
|
|
};
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
#ifdef COMPILE_DL_MYSQLI
|
|
|
|
ZEND_GET_MODULE(mysqli)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* {{{ PHP_INI_BEGIN
|
|
|
|
*/
|
|
|
|
PHP_INI_BEGIN()
|
2003-03-07 13:15:28 +08:00
|
|
|
STD_PHP_INI_ENTRY_EX("mysqli.max_links", "-1", PHP_INI_SYSTEM, OnUpdateLong, max_links, zend_mysqli_globals, mysqli_globals, display_link_numbers)
|
2003-02-12 08:45:53 +08:00
|
|
|
STD_PHP_INI_ENTRY("mysqli.default_host", NULL, PHP_INI_ALL, OnUpdateString, default_host, zend_mysqli_globals, mysqli_globals)
|
|
|
|
STD_PHP_INI_ENTRY("mysqli.default_user", NULL, PHP_INI_ALL, OnUpdateString, default_user, zend_mysqli_globals, mysqli_globals)
|
|
|
|
STD_PHP_INI_ENTRY("mysqli.default_pw", NULL, PHP_INI_ALL, OnUpdateString, default_pw, zend_mysqli_globals, mysqli_globals)
|
2003-03-07 13:15:28 +08:00
|
|
|
STD_PHP_INI_ENTRY("mysqli.default_port", "3306", PHP_INI_ALL, OnUpdateLong, default_port, zend_mysqli_globals, mysqli_globals)
|
2003-02-12 08:45:53 +08:00
|
|
|
STD_PHP_INI_ENTRY("mysqli.default_socket", NULL, PHP_INI_ALL, OnUpdateStringUnempty, default_socket, zend_mysqli_globals, mysqli_globals)
|
2004-02-26 19:40:35 +08:00
|
|
|
STD_PHP_INI_BOOLEAN("mysqli.reconnect", "0", PHP_INI_SYSTEM, OnUpdateLong, reconnect, zend_mysqli_globals, mysqli_globals)
|
2003-02-12 08:45:53 +08:00
|
|
|
PHP_INI_END()
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ php_mysqli_init_globals
|
|
|
|
*/
|
|
|
|
static void php_mysqli_init_globals(zend_mysqli_globals *mysqli_globals)
|
|
|
|
{
|
|
|
|
mysqli_globals->num_links = 0;
|
|
|
|
mysqli_globals->max_links = 0;
|
|
|
|
mysqli_globals->default_port = 0;
|
|
|
|
mysqli_globals->default_host = NULL;
|
|
|
|
mysqli_globals->default_user = NULL;
|
|
|
|
mysqli_globals->default_pw = NULL;
|
|
|
|
mysqli_globals->default_socket = NULL;
|
2004-02-26 19:40:35 +08:00
|
|
|
mysqli_globals->reconnect = 0;
|
2003-12-13 08:28:21 +08:00
|
|
|
mysqli_globals->report_mode = 0;
|
|
|
|
mysqli_globals->report_ht = 0;
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
mysqli_globals->multi_query = 0;
|
2005-01-07 22:59:59 +08:00
|
|
|
#ifdef HAVE_EMBEDDED_MYSQLI
|
|
|
|
mysqli_globals->embedded = 1;
|
|
|
|
#else
|
|
|
|
mysqli_globals->embedded = 0;
|
|
|
|
#endif
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ PHP_MINIT_FUNCTION
|
|
|
|
*/
|
|
|
|
PHP_MINIT_FUNCTION(mysqli)
|
|
|
|
{
|
2005-01-07 22:59:59 +08:00
|
|
|
zend_class_entry *ce,cex;
|
2004-12-26 00:42:53 +08:00
|
|
|
zend_object_handlers *std_hnd = zend_get_std_object_handlers();
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
ZEND_INIT_MODULE_GLOBALS(mysqli, php_mysqli_init_globals, NULL);
|
|
|
|
REGISTER_INI_ENTRIES();
|
|
|
|
|
|
|
|
memcpy(&mysqli_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
|
2004-06-06 02:31:56 +08:00
|
|
|
mysqli_object_handlers.clone_obj = NULL;
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
mysqli_object_handlers.read_property = mysqli_read_property;
|
|
|
|
mysqli_object_handlers.write_property = mysqli_write_property;
|
2004-12-26 00:42:53 +08:00
|
|
|
mysqli_object_handlers.get_property_ptr_ptr = std_hnd->get_property_ptr_ptr;
|
2004-06-24 00:47:25 +08:00
|
|
|
mysqli_object_handlers.get_constructor = php_mysqli_constructor_get;
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
|
|
|
|
zend_hash_init(&classes, 0, NULL, NULL, 1);
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2005-01-07 22:59:59 +08:00
|
|
|
INIT_CLASS_ENTRY(cex, "mysqli_sql_exception", mysqli_exception_methods);
|
|
|
|
#ifdef HAVE_SPL
|
|
|
|
mysqli_exception_class_entry = zend_register_internal_class_ex(&cex, spl_ce_RuntimeException, NULL TSRMLS_CC);
|
|
|
|
#else
|
|
|
|
mysqli_exception_class_entry = zend_register_internal_class_ex(&cex, zend_exception_get_default(), NULL TSRMLS_CC);
|
|
|
|
#endif
|
|
|
|
mysqli_exception_class_entry->ce_flags |= ZEND_ACC_FINAL;
|
|
|
|
zend_declare_property_long(mysqli_exception_class_entry, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED TSRMLS_CC);
|
|
|
|
zend_declare_property_string(mysqli_exception_class_entry, "sqlstate", sizeof("sqlstate")-1, "00000", ZEND_ACC_PROTECTED TSRMLS_CC);
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
|
2005-01-07 22:59:59 +08:00
|
|
|
REGISTER_MYSQLI_CLASS_ENTRY("mysqli_driver", mysqli_driver_class_entry, mysqli_driver_methods);
|
|
|
|
ce = mysqli_driver_class_entry;
|
|
|
|
zend_hash_init(&mysqli_driver_properties, 0, NULL, NULL, 1);
|
|
|
|
MYSQLI_ADD_PROPERTIES(&mysqli_driver_properties, mysqli_driver_property_entries);
|
|
|
|
zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_driver_properties, sizeof(mysqli_driver_properties), NULL);
|
|
|
|
ce->ce_flags |= ZEND_ACC_FINAL;
|
|
|
|
|
|
|
|
REGISTER_MYSQLI_CLASS_ENTRY("mysqli", mysqli_link_class_entry, mysqli_link_methods);
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
ce = mysqli_link_class_entry;
|
|
|
|
zend_hash_init(&mysqli_link_properties, 0, NULL, NULL, 1);
|
|
|
|
MYSQLI_ADD_PROPERTIES(&mysqli_link_properties, mysqli_link_property_entries);
|
|
|
|
zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_link_properties, sizeof(mysqli_link_properties), NULL);
|
|
|
|
|
2005-01-07 22:59:59 +08:00
|
|
|
REGISTER_MYSQLI_CLASS_ENTRY("mysqli_warning", mysqli_warning_class_entry, mysqli_warning_methods);
|
|
|
|
ce = mysqli_warning_class_entry;
|
|
|
|
ce->ce_flags |= ZEND_ACC_FINAL;
|
|
|
|
zend_hash_init(&mysqli_warning_properties, 0, NULL, NULL, 1);
|
|
|
|
MYSQLI_ADD_PROPERTIES(&mysqli_warning_properties, mysqli_warning_property_entries);
|
|
|
|
zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_warning_properties, sizeof(mysqli_warning_properties), NULL);
|
|
|
|
ce->ce_flags |= ZEND_ACC_FINAL;
|
|
|
|
|
2003-02-12 08:45:53 +08:00
|
|
|
REGISTER_MYSQLI_CLASS_ENTRY("mysqli_result", mysqli_result_class_entry, mysqli_result_methods);
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
ce = mysqli_result_class_entry;
|
|
|
|
zend_hash_init(&mysqli_result_properties, 0, NULL, NULL, 1);
|
|
|
|
MYSQLI_ADD_PROPERTIES(&mysqli_result_properties, mysqli_result_property_entries);
|
|
|
|
zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_result_properties, sizeof(mysqli_result_properties), NULL);
|
|
|
|
|
2003-02-12 08:45:53 +08:00
|
|
|
REGISTER_MYSQLI_CLASS_ENTRY("mysqli_stmt", mysqli_stmt_class_entry, mysqli_stmt_methods);
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
ce = mysqli_stmt_class_entry;
|
|
|
|
zend_hash_init(&mysqli_stmt_properties, 0, NULL, NULL, 1);
|
|
|
|
MYSQLI_ADD_PROPERTIES(&mysqli_stmt_properties, mysqli_stmt_property_entries);
|
|
|
|
zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_stmt_properties, sizeof(mysqli_stmt_properties), NULL);
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
/* mysqli_options */
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_READ_DEFAULT_GROUP", MYSQL_READ_DEFAULT_GROUP, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_READ_DEFAULT_FILE", MYSQL_READ_DEFAULT_FILE, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_OPT_CONNECT_TIMEOUT", MYSQL_OPT_CONNECT_TIMEOUT, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_OPT_LOCAL_INFILE", MYSQL_OPT_LOCAL_INFILE, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_INIT_COMMAND", MYSQL_INIT_COMMAND, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
|
|
|
/* mysqli_real_connect flags */
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_CLIENT_SSL", CLIENT_SSL, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_CLIENT_COMPRESS",CLIENT_COMPRESS, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_CLIENT_INTERACTIVE", CLIENT_INTERACTIVE, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_CLIENT_IGNORE_SPACE", CLIENT_IGNORE_SPACE, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_CLIENT_NO_SCHEMA", CLIENT_NO_SCHEMA, CONST_CS | CONST_PERSISTENT);
|
2004-08-09 12:34:01 +08:00
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_CLIENT_FOUND_ROWS", CLIENT_FOUND_ROWS, CONST_CS | CONST_PERSISTENT);
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
/* for mysqli_query */
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_STORE_RESULT", 0, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_USE_RESULT", 1, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
|
|
|
/* for mysqli_fetch_assoc */
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_ASSOC", MYSQLI_ASSOC, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_NUM", MYSQLI_NUM, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_BOTH", MYSQLI_BOTH, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
2004-07-07 16:02:27 +08:00
|
|
|
/* for mysqli_stmt_set_attr */
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH", STMT_ATTR_UPDATE_MAX_LENGTH, CONST_CS | CONST_PERSISTENT);
|
2004-07-23 20:47:36 +08:00
|
|
|
|
|
|
|
#ifdef STMT_ATTR_CURSOR_TYPE
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_STMT_ATTR_CURSOR_TYPE", STMT_ATTR_CURSOR_TYPE, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_CURSOR_TYPE_NO_CURSOR", CURSOR_TYPE_NO_CURSOR, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_CURSOR_TYPE_READ_ONLY", CURSOR_TYPE_READ_ONLY, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_CURSOR_TYPE_FOR_UPDATE", CURSOR_TYPE_FOR_UPDATE, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_CURSOR_TYPE_SCROLLABLE", CURSOR_TYPE_SCROLLABLE, CONST_CS | CONST_PERSISTENT);
|
|
|
|
#endif
|
2003-02-12 08:45:53 +08:00
|
|
|
|
|
|
|
/* column information */
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_NOT_NULL_FLAG", NOT_NULL_FLAG, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_PRI_KEY_FLAG", PRI_KEY_FLAG, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_UNIQUE_KEY_FLAG", UNIQUE_KEY_FLAG, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_MULTIPLE_KEY_FLAG", MULTIPLE_KEY_FLAG, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_BLOB_FLAG", BLOB_FLAG, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_UNSIGNED_FLAG", UNSIGNED_FLAG, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_ZEROFILL_FLAG", ZEROFILL_FLAG, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_AUTO_INCREMENT_FLAG", AUTO_INCREMENT_FLAG, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TIMESTAMP_FLAG", TIMESTAMP_FLAG, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_SET_FLAG", SET_FLAG, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_NUM_FLAG", NUM_FLAG, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_PART_KEY_FLAG", PART_KEY_FLAG, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_GROUP_FLAG", GROUP_FLAG, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_DECIMAL", FIELD_TYPE_DECIMAL, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_TINY", FIELD_TYPE_TINY, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_SHORT", FIELD_TYPE_SHORT, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_LONG", FIELD_TYPE_LONG, CONST_CS | CONST_PERSISTENT);
|
2004-01-29 06:51:54 +08:00
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_FLOAT", FIELD_TYPE_FLOAT, CONST_CS | CONST_PERSISTENT);
|
2003-02-12 08:45:53 +08:00
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_DOUBLE", FIELD_TYPE_DOUBLE, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_NULL", FIELD_TYPE_NULL, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_TIMESTAMP", FIELD_TYPE_TIMESTAMP, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_LONGLONG", FIELD_TYPE_LONGLONG, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_INT24", FIELD_TYPE_INT24, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_DATE", FIELD_TYPE_DATE, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_TIME", FIELD_TYPE_TIME, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_DATETIME", FIELD_TYPE_DATETIME , CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_YEAR", FIELD_TYPE_YEAR, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_NEWDATE", FIELD_TYPE_NEWDATE, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_ENUM", FIELD_TYPE_ENUM, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_SET", FIELD_TYPE_SET, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_TINY_BLOB", FIELD_TYPE_TINY_BLOB, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_MEDIUM_BLOB", FIELD_TYPE_MEDIUM_BLOB, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_LONG_BLOB", FIELD_TYPE_LONG_BLOB, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_BLOB", FIELD_TYPE_BLOB, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_VAR_STRING", FIELD_TYPE_VAR_STRING, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_STRING", FIELD_TYPE_STRING, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_CHAR", FIELD_TYPE_CHAR, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_INTERVAL", FIELD_TYPE_INTERVAL, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_GEOMETRY", FIELD_TYPE_GEOMETRY, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
|
|
|
/* replication */
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_RPL_MASTER", MYSQL_RPL_MASTER, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_RPL_SLAVE", MYSQL_RPL_SLAVE, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_RPL_ADMIN", MYSQL_RPL_ADMIN, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
|
|
|
/* bind blob support */
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_NO_DATA", MYSQL_NO_DATA, CONST_CS | CONST_PERSISTENT);
|
2003-03-11 09:19:21 +08:00
|
|
|
|
2003-12-13 08:28:21 +08:00
|
|
|
/* reporting */
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_REPORT_INDEX", MYSQLI_REPORT_INDEX, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_REPORT_ERROR", MYSQLI_REPORT_ERROR, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_REPORT_ALL", MYSQLI_REPORT_ALL, CONST_CS | CONST_PERSISTENT);
|
2004-01-29 06:51:54 +08:00
|
|
|
REGISTER_LONG_CONSTANT("MYSQLI_REPORT_OFF", 0, CONST_CS | CONST_PERSISTENT);
|
2003-03-11 09:19:21 +08:00
|
|
|
|
2003-02-12 08:45:53 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ PHP_MSHUTDOWN_FUNCTION
|
|
|
|
*/
|
|
|
|
PHP_MSHUTDOWN_FUNCTION(mysqli)
|
|
|
|
{
|
2005-01-07 22:59:59 +08:00
|
|
|
// zend_hash_destroy(&mysqli_driver_properties);
|
2003-12-10 18:06:07 +08:00
|
|
|
zend_hash_destroy(&mysqli_result_properties);
|
|
|
|
zend_hash_destroy(&mysqli_stmt_properties);
|
2005-01-07 22:59:59 +08:00
|
|
|
zend_hash_destroy(&mysqli_warning_properties);
|
|
|
|
zend_hash_destroy(&mysqli_link_properties);
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
zend_hash_destroy(&classes);
|
|
|
|
|
2003-02-12 08:45:53 +08:00
|
|
|
UNREGISTER_INI_ENTRIES();
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ PHP_RINIT_FUNCTION
|
|
|
|
*/
|
|
|
|
PHP_RINIT_FUNCTION(mysqli)
|
|
|
|
{
|
2003-02-15 00:49:09 +08:00
|
|
|
MyG(error_msg) = NULL;
|
|
|
|
MyG(error_no) = 0;
|
|
|
|
|
2003-02-12 08:45:53 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ PHP_RSHUTDOWN_FUNCTION
|
|
|
|
*/
|
|
|
|
PHP_RSHUTDOWN_FUNCTION(mysqli)
|
|
|
|
{
|
2003-02-15 00:49:09 +08:00
|
|
|
if (MyG(error_msg)) {
|
|
|
|
efree(MyG(error_msg));
|
|
|
|
}
|
2003-02-12 08:45:53 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ PHP_MINFO_FUNCTION
|
|
|
|
*/
|
|
|
|
PHP_MINFO_FUNCTION(mysqli)
|
|
|
|
{
|
|
|
|
php_info_print_table_start();
|
|
|
|
php_info_print_table_header(2, "MysqlI Support", "enabled");
|
|
|
|
php_info_print_table_row(2, "Client API version", mysql_get_client_info());
|
|
|
|
php_info_print_table_row(2, "MYSQLI_SOCKET", MYSQL_UNIX_ADDR);
|
|
|
|
|
|
|
|
|
|
|
|
php_info_print_table_end();
|
|
|
|
|
|
|
|
DISPLAY_INI_ENTRIES();
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2004-12-26 21:16:40 +08:00
|
|
|
/* {{{ mixed mysqli_stmt_construct()
|
|
|
|
constructor for statement object.
|
|
|
|
Parameters:
|
|
|
|
object -> mysqli_init
|
|
|
|
object, query -> mysqli_prepare
|
|
|
|
*/
|
|
|
|
ZEND_FUNCTION(mysqli_stmt_construct)
|
|
|
|
{
|
|
|
|
MY_MYSQL *mysql;
|
|
|
|
zval **mysql_link, **statement;
|
|
|
|
MY_STMT *stmt;
|
|
|
|
MYSQLI_RESOURCE *mysqli_resource;
|
|
|
|
|
|
|
|
switch (ZEND_NUM_ARGS())
|
|
|
|
{
|
|
|
|
case 1: /* mysql_stmt_init */
|
|
|
|
if (zend_get_parameters_ex(1, &mysql_link)==FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, mysql_link, "mysqli_link");
|
|
|
|
|
|
|
|
stmt = (MY_STMT *)ecalloc(1,sizeof(MY_STMT));
|
|
|
|
|
|
|
|
stmt->stmt = mysql_stmt_init(mysql->mysql);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (zend_get_parameters_ex(2, &mysql_link, &statement)==FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, mysql_link, "mysqli_link");
|
|
|
|
convert_to_string_ex(statement);
|
|
|
|
|
|
|
|
stmt = (MY_STMT *)ecalloc(1,sizeof(MY_STMT));
|
|
|
|
|
|
|
|
if ((stmt->stmt = mysql_stmt_init(mysql->mysql))) {
|
|
|
|
mysql_stmt_prepare(stmt->stmt, Z_STRVAL_PP(statement), strlen(Z_STRVAL_PP(statement)));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stmt->stmt) {
|
|
|
|
efree(stmt);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
|
|
|
|
mysqli_resource->ptr = (void *)stmt;
|
|
|
|
|
|
|
|
((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->ptr = mysqli_resource;
|
|
|
|
((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->valid = 1;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ mixed mysqli_result_construct()
|
|
|
|
constructor for result object.
|
|
|
|
Parameters:
|
|
|
|
object [, mode] -> mysqli_store/use_result
|
|
|
|
*/
|
|
|
|
ZEND_FUNCTION(mysqli_result_construct)
|
|
|
|
{
|
|
|
|
MY_MYSQL *mysql;
|
|
|
|
MYSQL_RES *result;
|
|
|
|
zval **mysql_link, **mode;
|
|
|
|
MYSQLI_RESOURCE *mysqli_resource;
|
|
|
|
int resmode = MYSQLI_STORE_RESULT;
|
|
|
|
|
|
|
|
switch (ZEND_NUM_ARGS()) {
|
|
|
|
case 1:
|
|
|
|
if (zend_get_parameters_ex(1, &mysql_link)==FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (zend_get_parameters_ex(2, &mysql_link, &mode)==FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resmode = Z_LVAL_PP(mode);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, mysql_link, "mysqli_link");
|
|
|
|
|
|
|
|
result = (resmode == MYSQLI_STORE_RESULT) ? mysql_store_result(mysql->mysql) :
|
|
|
|
mysql_use_result(mysql->mysql);
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
|
|
|
|
mysqli_resource->ptr = (void *)result;
|
|
|
|
|
|
|
|
((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->ptr = mysqli_resource;
|
|
|
|
((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->valid = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-02-12 08:45:53 +08:00
|
|
|
/* {{{ php_mysqli_fetch_into_hash
|
|
|
|
*/
|
2003-09-07 03:34:48 +08:00
|
|
|
void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags, int into_object)
|
2003-02-12 08:45:53 +08:00
|
|
|
{
|
2003-03-09 07:33:12 +08:00
|
|
|
MYSQL_RES *result;
|
|
|
|
zval *mysql_result;
|
|
|
|
int fetchtype;
|
|
|
|
unsigned int i;
|
|
|
|
MYSQL_FIELD *fields;
|
|
|
|
MYSQL_ROW row;
|
|
|
|
unsigned long *field_len;
|
2003-09-07 03:34:48 +08:00
|
|
|
zval *ctor_params = NULL;
|
|
|
|
zend_class_entry *ce = NULL;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-09-07 03:34:48 +08:00
|
|
|
if (into_object) {
|
|
|
|
char *class_name;
|
|
|
|
int class_name_len;
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-09-07 03:34:48 +08:00
|
|
|
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) {
|
2005-01-07 22:59:59 +08:00
|
|
|
// php_std_error_handling();
|
2003-09-07 03:34:48 +08:00
|
|
|
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) {
|
2005-01-07 22:59:59 +08:00
|
|
|
//php_std_error_handling();
|
2003-09-07 03:34:48 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
fetchtype = override_flags;
|
|
|
|
} else {
|
2004-08-15 13:48:16 +08:00
|
|
|
fetchtype = MYSQLI_BOTH;
|
2003-09-07 03:34:48 +08:00
|
|
|
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|l", &mysql_result, mysqli_result_class_entry, &fetchtype) == FAILURE) {
|
2005-01-07 22:59:59 +08:00
|
|
|
// php_std_error_handling();
|
2003-09-07 03:34:48 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
2003-12-13 08:28:21 +08:00
|
|
|
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result");
|
2003-02-12 08:45:53 +08:00
|
|
|
|
2003-02-22 15:31:01 +08:00
|
|
|
if (!(row = mysql_fetch_row(result))) {
|
- Added multiquery support:
mysqli_multi_query
mysqli_more_results
mysqli_next_results
- added read-only properties (and removed methods)
object mysql
affected_rows
client_flags
client_version
errno, error,
host, host_info, info
server_capabilities, server_version
sqlstate, port, protocol_version,
server_language
thread_id, user, warning_count
object result
current_field, field_count,
lengths, num_rows, type
object stmt
query, param_count, field_count,
id, errno, error, sqlstate
- added constructor
- minor fixes, prototypes
2003-11-23 05:20:07 +08:00
|
|
|
RETURN_NULL();
|
2003-02-22 15:31:01 +08:00
|
|
|
}
|
2003-03-09 07:33:12 +08:00
|
|
|
|
2003-12-13 08:28:21 +08:00
|
|
|
if (fetchtype & MYSQLI_ASSOC) {
|
|
|
|
fields = mysql_fetch_fields(result);
|
|
|
|
}
|
|
|
|
|
2003-02-22 15:31:01 +08:00
|
|
|
array_init(return_value);
|
2003-02-12 08:45:53 +08:00
|
|
|
field_len = mysql_fetch_lengths(result);
|
|
|
|
|
2003-02-15 00:49:09 +08:00
|
|
|
for (i = 0; i < mysql_num_fields(result); i++) {
|
2003-02-12 08:45:53 +08:00
|
|
|
if (row[i]) {
|
2003-11-08 01:20:49 +08:00
|
|
|
zval *res;
|
|
|
|
|
|
|
|
MAKE_STD_ZVAL(res);
|
|
|
|
|
2003-02-12 08:45:53 +08:00
|
|
|
/* check if we need magic quotes */
|
|
|
|
if (PG(magic_quotes_runtime)) {
|
2003-11-08 01:20:49 +08:00
|
|
|
Z_TYPE_P(res) = IS_STRING;
|
|
|
|
Z_STRVAL_P(res) = php_addslashes(row[i], field_len[i], &Z_STRLEN_P(res), 0 TSRMLS_CC);
|
2003-02-15 00:49:09 +08:00
|
|
|
} else {
|
2003-11-08 01:20:49 +08:00
|
|
|
ZVAL_STRINGL(res, row[i], field_len[i], 1);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
2003-11-08 01:20:49 +08:00
|
|
|
|
2003-02-12 08:45:53 +08:00
|
|
|
if (fetchtype & MYSQLI_NUM) {
|
2003-11-08 01:20:49 +08:00
|
|
|
add_index_zval(return_value, i, res);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
if (fetchtype & MYSQLI_ASSOC) {
|
2003-11-08 01:20:49 +08:00
|
|
|
if (fetchtype & MYSQLI_NUM) {
|
|
|
|
ZVAL_ADDREF(res);
|
|
|
|
}
|
|
|
|
add_assoc_zval(return_value, fields[i].name, res);
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
2003-02-15 00:49:09 +08:00
|
|
|
} else {
|
2003-02-12 08:45:53 +08:00
|
|
|
if (fetchtype & MYSQLI_NUM) {
|
|
|
|
add_index_null(return_value, i);
|
|
|
|
}
|
|
|
|
if (fetchtype & MYSQLI_ASSOC) {
|
|
|
|
add_assoc_null(return_value, fields[i].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-03-09 07:33:12 +08:00
|
|
|
|
2003-09-07 03:34:48 +08:00
|
|
|
if (into_object) {
|
|
|
|
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_pp = &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 *ht = Z_ARRVAL_P(ctor_params);
|
|
|
|
Bucket *p;
|
|
|
|
|
|
|
|
fci.param_count = 0;
|
2004-01-01 03:45:46 +08:00
|
|
|
fci.params = safe_emalloc(sizeof(zval*), ht->nNumOfElements, 0);
|
2003-09-07 03:34:48 +08:00
|
|
|
p = 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(), "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.object_pp = &return_value;
|
|
|
|
|
|
|
|
if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) {
|
|
|
|
zend_throw_exception_ex(zend_exception_get_default(), 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(), 0 TSRMLS_CC, "Class %s does not have a constructor hence you cannot use ctor_params", ce->name);
|
|
|
|
}
|
|
|
|
}
|
2003-02-12 08:45:53 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-02-15 00:49:09 +08:00
|
|
|
/* {{{ php_mysqli_set_error
|
|
|
|
*/
|
|
|
|
PHP_MYSQLI_API void php_mysqli_set_error(long mysql_errno, char *mysql_err TSRMLS_DC)
|
|
|
|
{
|
|
|
|
MyG(error_no) = mysql_errno;
|
|
|
|
if (MyG(error_msg)) {
|
|
|
|
efree(MyG(error_msg));
|
|
|
|
}
|
|
|
|
MyG(error_msg) = estrdup(mysql_err);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2004-06-06 02:31:56 +08:00
|
|
|
#define ALLOC_CALLBACK_ARGS(a, b, c)\
|
|
|
|
if (c) {\
|
|
|
|
a = (zval ***)safe_emalloc(c, sizeof(zval **), 0);\
|
|
|
|
for (i = b; i < c; i++) {\
|
|
|
|
a[i] = emalloc(sizeof(zval *));\
|
|
|
|
MAKE_STD_ZVAL(*a[i]);\
|
|
|
|
}\
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FREE_CALLBACK_ARGS(a, b, c)\
|
|
|
|
if (a) {\
|
|
|
|
for (i=b; i < c; i++) {\
|
|
|
|
zval_ptr_dtor(a[i]);\
|
|
|
|
efree(a[i]);\
|
|
|
|
}\
|
|
|
|
efree(a);\
|
|
|
|
}
|
|
|
|
|
|
|
|
#define LOCAL_INFILE_ERROR_MSG(source,dest)\
|
|
|
|
memset(source, 0, LOCAL_INFILE_ERROR_LEN);\
|
|
|
|
memcpy(source, dest, LOCAL_INFILE_ERROR_LEN-1);
|
|
|
|
|
2004-08-25 21:57:35 +08:00
|
|
|
/* {{{ void php_set_local_infile_handler_default
|
|
|
|
*/
|
|
|
|
void php_set_local_infile_handler_default(MY_MYSQL *mysql) {
|
|
|
|
/* 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);
|
|
|
|
mysql->li_read = NULL;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2004-06-06 02:31:56 +08:00
|
|
|
/* {{{ php_local_infile_init
|
|
|
|
*/
|
|
|
|
int php_local_infile_init(void **ptr, const char *filename, void *userdata)
|
|
|
|
{
|
|
|
|
mysqli_local_infile *data;
|
|
|
|
MY_MYSQL *mysql;
|
2004-08-25 21:57:35 +08:00
|
|
|
php_stream_context *context = NULL;
|
2004-06-06 02:31:56 +08:00
|
|
|
|
2004-06-06 14:40:19 +08:00
|
|
|
TSRMLS_FETCH();
|
|
|
|
|
2004-06-06 02:31:56 +08:00
|
|
|
/* save pointer to MY_MYSQL structure (userdata) */
|
|
|
|
if (!(*ptr= data= ((mysqli_local_infile *)calloc(1, sizeof(mysqli_local_infile))))) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-08-25 21:57:35 +08:00
|
|
|
if (!(mysql = (MY_MYSQL *)userdata)) {
|
2004-06-06 02:31:56 +08:00
|
|
|
LOCAL_INFILE_ERROR_MSG(data->error_msg, ER(CR_UNKNOWN_ERROR));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-08-25 21:57:35 +08:00
|
|
|
/* check open_basedir */
|
|
|
|
if (PG(open_basedir)) {
|
|
|
|
if (php_check_open_basedir_ex(filename, 0 TSRMLS_CC) == -1) {
|
|
|
|
LOCAL_INFILE_ERROR_MSG(data->error_msg, "open_basedir restriction in effect. Unable to open file");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2004-06-06 02:31:56 +08:00
|
|
|
|
2004-08-25 21:57:35 +08:00
|
|
|
mysql->li_stream = php_stream_open_wrapper_ex((char *)filename, "r", 0, NULL, context);
|
2004-06-06 02:31:56 +08:00
|
|
|
|
2004-08-25 21:57:35 +08:00
|
|
|
if (mysql->li_stream == NULL) {
|
|
|
|
return 1;
|
2004-06-06 02:31:56 +08:00
|
|
|
}
|
|
|
|
|
2004-08-25 21:57:35 +08:00
|
|
|
data->userdata = mysql;
|
2004-06-06 02:31:56 +08:00
|
|
|
|
2004-08-25 21:57:35 +08:00
|
|
|
return 0;
|
2004-06-06 02:31:56 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2005-01-07 22:59:59 +08:00
|
|
|
/* {{{ int php_local_infile_read */
|
2004-06-06 02:31:56 +08:00
|
|
|
int php_local_infile_read(void *ptr, char *buf, uint buf_len)
|
|
|
|
{
|
|
|
|
mysqli_local_infile *data;
|
|
|
|
MY_MYSQL *mysql;
|
|
|
|
zval ***callback_args;
|
2004-08-25 21:57:35 +08:00
|
|
|
zval *retval;
|
|
|
|
zval *fp;
|
2004-06-06 02:31:56 +08:00
|
|
|
int argc = 4;
|
|
|
|
int i;
|
|
|
|
long rc;
|
|
|
|
|
2004-06-06 14:40:19 +08:00
|
|
|
TSRMLS_FETCH();
|
|
|
|
|
2004-06-06 02:31:56 +08:00
|
|
|
data= (mysqli_local_infile *)ptr;
|
|
|
|
mysql = data->userdata;
|
|
|
|
|
2004-08-25 21:57:35 +08:00
|
|
|
/* default processing */
|
|
|
|
if (!mysql->li_read) {
|
|
|
|
int count;
|
|
|
|
|
|
|
|
count = (int)php_stream_read(mysql->li_stream, buf, buf_len);
|
|
|
|
|
|
|
|
if (count < 0) {
|
|
|
|
LOCAL_INFILE_ERROR_MSG(data->error_msg, ER(2));
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2004-06-06 02:31:56 +08:00
|
|
|
ALLOC_CALLBACK_ARGS(callback_args, 1, argc);
|
|
|
|
|
|
|
|
/* set parameters: filepointer, buffer, buffer_len, errormsg */
|
|
|
|
|
2004-08-25 21:57:35 +08:00
|
|
|
MAKE_STD_ZVAL(fp);
|
|
|
|
php_stream_to_zval(mysql->li_stream, fp);
|
|
|
|
callback_args[0] = &fp;
|
2004-06-06 02:31:56 +08:00
|
|
|
ZVAL_STRING(*callback_args[1], "", 1);
|
|
|
|
ZVAL_LONG(*callback_args[2], buf_len);
|
|
|
|
ZVAL_STRING(*callback_args[3], "", 1);
|
|
|
|
|
|
|
|
if (call_user_function_ex(EG(function_table),
|
|
|
|
NULL,
|
2004-08-25 21:57:35 +08:00
|
|
|
mysql->li_read,
|
2004-06-06 02:31:56 +08:00
|
|
|
&retval,
|
|
|
|
argc,
|
|
|
|
callback_args,
|
|
|
|
0,
|
|
|
|
NULL TSRMLS_CC) == SUCCESS) {
|
|
|
|
|
|
|
|
rc = Z_LVAL_P(retval);
|
|
|
|
zval_ptr_dtor(&retval);
|
|
|
|
|
|
|
|
if (rc > 0) {
|
|
|
|
if (rc > buf_len) {
|
|
|
|
/* check buffer overflow */
|
|
|
|
LOCAL_INFILE_ERROR_MSG(data->error_msg, "Read buffer too large");
|
|
|
|
rc = -1;
|
|
|
|
} else {
|
|
|
|
memcpy(buf, Z_STRVAL_P(*callback_args[1]), rc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rc < 0) {
|
|
|
|
LOCAL_INFILE_ERROR_MSG(data->error_msg, Z_STRVAL_P(*callback_args[3]));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOCAL_INFILE_ERROR_MSG(data->error_msg, "Can't execute load data local init callback function");
|
|
|
|
rc = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
FREE_CALLBACK_ARGS(callback_args, 1, argc);
|
2004-08-25 21:57:35 +08:00
|
|
|
efree(fp);
|
2004-06-06 02:31:56 +08:00
|
|
|
return rc;
|
|
|
|
}
|
2005-01-07 22:59:59 +08:00
|
|
|
/* }}} */
|
2004-06-06 02:31:56 +08:00
|
|
|
|
|
|
|
/* {{{ php_local_infile_error
|
|
|
|
*/
|
|
|
|
int php_local_infile_error(void *ptr, char *error_msg, uint error_msg_len)
|
|
|
|
{
|
|
|
|
mysqli_local_infile *data = (mysqli_local_infile *) ptr;
|
2004-08-25 21:57:35 +08:00
|
|
|
|
2004-06-06 02:31:56 +08:00
|
|
|
if (data) {
|
|
|
|
strcpy(error_msg, data->error_msg);
|
|
|
|
return 2000;
|
|
|
|
}
|
|
|
|
strcpy(error_msg, ER(CR_OUT_OF_MEMORY));
|
|
|
|
return CR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ php_local_infile_end
|
|
|
|
*/
|
|
|
|
void php_local_infile_end(void *ptr)
|
|
|
|
{
|
|
|
|
mysqli_local_infile *data;
|
|
|
|
MY_MYSQL *mysql;
|
|
|
|
|
2004-06-06 14:40:19 +08:00
|
|
|
TSRMLS_FETCH();
|
|
|
|
|
2004-06-06 02:31:56 +08:00
|
|
|
data= (mysqli_local_infile *)ptr;
|
|
|
|
|
2004-08-25 21:57:35 +08:00
|
|
|
if (!(mysql = data->userdata)) {
|
|
|
|
return;
|
2004-06-06 02:31:56 +08:00
|
|
|
}
|
|
|
|
|
2004-08-25 21:57:35 +08:00
|
|
|
php_stream_close(mysql->li_stream);
|
|
|
|
return;
|
2004-06-06 02:31:56 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-02-12 08:45:53 +08:00
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
* vim600: noet sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: noet sw=4 ts=4
|
|
|
|
*/
|