Refactor MySQLi (incompleted, only compilable now)

This commit is contained in:
Xinchen Hui 2014-05-11 14:53:18 +08:00
parent e9274de503
commit 2402d6cbbc
13 changed files with 616 additions and 854 deletions

View File

@ -605,6 +605,7 @@ END_EXTERN_C()
#define RETVAL_STRINGL(s, l) ZVAL_STRINGL(return_value, s, l)
#define RETVAL_EMPTY_STRING() ZVAL_EMPTY_STRING(return_value)
#define RETVAL_RES(r) ZVAL_RES(return_value, r)
#define RETVAL_OBJ(r) ZVAL_OBJ(return_value, r)
#define RETVAL_ZVAL(zv, copy, dtor) ZVAL_ZVAL(return_value, zv, copy, dtor)
#define RETVAL_FALSE ZVAL_BOOL(return_value, 0)
#define RETVAL_TRUE ZVAL_BOOL(return_value, 1)
@ -620,6 +621,7 @@ END_EXTERN_C()
#define RETURN_STRINGL(s, l) { RETVAL_STRINGL(s, l); return; }
#define RETURN_EMPTY_STRING() { RETVAL_EMPTY_STRING(); return; }
#define RETURN_RES(r) { RETVAL_RES(r); return; }
#define RETURN_OBJ(r) { RETVAL_OBJ(r); return; }
#define RETURN_ZVAL(zv, copy, dtor) { RETVAL_ZVAL(zv, copy, dtor); return; }
#define RETURN_FALSE { RETVAL_FALSE; return; }
#define RETURN_TRUE { RETVAL_TRUE; return; }

View File

@ -218,7 +218,6 @@ typedef struct _zend_property_info {
zend_class_entry *ce;
} zend_property_info;
typedef struct _zend_arg_info {
const char *name; // TODO: convert into zend_string ???
zend_uint name_len;

View File

@ -39,29 +39,23 @@
ZEND_DECLARE_MODULE_GLOBALS(mysqli)
static PHP_GINIT_FUNCTION(mysqli);
#define MYSQLI_ADD_PROPERTIES(a,b) \
#define MYSQLI_ADD_PROPERTIES(a, b) \
{ \
int i = 0; \
while (b[i].pname != NULL) { \
mysqli_add_property((a), (b)[i].pname, (b)[i].pname_length, \
(mysqli_read_t)(b)[i].r_func, (mysqli_write_t)(b)[i].w_func TSRMLS_CC); \
i++; \
}\
} \
}
#define MYSQLI_ADD_PROPERTIES_INFO(a,b) \
{ \
int i = 0; \
while (b[i].name != NULL) { \
zend_declare_property_null((a), (b)[i].name, (b)[i].name_length, ZEND_ACC_PUBLIC TSRMLS_CC); \
i++; \
}\
}
static zend_object_handlers mysqli_object_handlers;
static HashTable classes;
static zend_object_handlers mysqli_object_handlers;
static zend_object_handlers mysqli_object_driver_handlers;
static zend_object_handlers mysqli_object_link_handlers;
static zend_object_handlers mysqli_object_result_handlers;
static zend_object_handlers mysqli_object_stmt_handlers;
static zend_object_handlers mysqli_object_warning_handlers;
static HashTable mysqli_driver_properties;
static HashTable mysqli_link_properties;
static HashTable mysqli_result_properties;
@ -76,12 +70,11 @@ zend_class_entry *mysqli_warning_class_entry;
zend_class_entry *mysqli_exception_class_entry;
typedef int (*mysqli_read_t)(mysqli_object *obj, zval **retval TSRMLS_DC);
typedef zval *(*mysqli_read_t)(mysqli_object *obj, zval *rv TSRMLS_DC);
typedef int (*mysqli_write_t)(mysqli_object *obj, zval *newval TSRMLS_DC);
typedef struct _mysqli_prop_handler {
char *name;
size_t name_len;
zend_string *name;
mysqli_read_t read_func;
mysqli_write_t write_func;
} mysqli_prop_handler;
@ -92,7 +85,7 @@ static int le_pmysqli;
/* Destructor for mysqli entries in free_links/used_links */
void php_mysqli_dtor_p_elements(void *data)
{
MYSQL *mysql = (MYSQL *) data;
MYSQL *mysql = (MYSQL *)data;
TSRMLS_FETCH();
mysqli_close(mysql, MYSQLI_CLOSE_IMPLICIT);
}
@ -100,8 +93,8 @@ void php_mysqli_dtor_p_elements(void *data)
ZEND_RSRC_DTOR_FUNC(php_mysqli_dtor)
{
if (rsrc->ptr) {
mysqli_plist_entry *plist = (mysqli_plist_entry *) rsrc->ptr;
if (res->ptr) {
mysqli_plist_entry *plist = (mysqli_plist_entry *)res->ptr;
zend_ptr_stack_clean(&plist->free_links, php_mysqli_dtor_p_elements, 0);
zend_ptr_stack_destroy(&plist->free_links);
free(plist);
@ -131,9 +124,7 @@ void php_free_stmt_bind_buffer(BIND_BUFFER bbuf, int type)
efree(bbuf.buf[i].val);
}
if (bbuf.vars[i]) {
zval_ptr_dtor(&bbuf.vars[i]);
}
zval_ptr_dtor(&bbuf.vars[i]);
}
if (bbuf.vars) {
@ -177,8 +168,8 @@ void php_clear_stmt_bind(MY_STMT *stmt TSRMLS_DC)
/* Clean output bind */
php_free_stmt_bind_buffer(stmt->result, FETCH_RESULT);
if (stmt->link_handle) {
zend_objects_store_del_ref_by_handle(stmt->link_handle TSRMLS_CC);
if (!Z_ISUNDEF(stmt->link_handle)) {
zval_ptr_dtor(&stmt->link_handle);
}
#endif
if (stmt->query) {
@ -194,24 +185,22 @@ void php_clear_mysql(MY_MYSQL *mysql) {
efree(mysql->hash_key);
mysql->hash_key = NULL;
}
if (mysql->li_read) {
if (!Z_ISUNDEF(mysql->li_read)) {
zval_ptr_dtor(&(mysql->li_read));
mysql->li_read = NULL;
ZVAL_UNDEF(&mysql->li_read);
}
}
/* }}} */
/* {{{ mysqli_objects_free_storage
*/
static void mysqli_objects_free_storage(void *object TSRMLS_DC)
static void mysqli_objects_free_storage(zend_object *object TSRMLS_DC)
{
zend_object *zo = (zend_object *)object;
mysqli_object *intern = (mysqli_object *)zo;
mysqli_object *intern = php_mysqli_fetch_object(object);
MYSQLI_RESOURCE *my_res = (MYSQLI_RESOURCE *)intern->ptr;
my_efree(my_res);
zend_object_std_dtor(&intern->zo TSRMLS_CC);
efree(intern);
}
/* }}} */
@ -219,10 +208,9 @@ static void mysqli_objects_free_storage(void *object TSRMLS_DC)
/* {{{ mysqli_link_free_storage
*/
static void mysqli_link_free_storage(void *object TSRMLS_DC)
static void mysqli_link_free_storage(zend_object *object TSRMLS_DC)
{
zend_object *zo = (zend_object *)object;
mysqli_object *intern = (mysqli_object *)zo;
mysqli_object *intern = php_mysqli_fetch_object(object);
MYSQLI_RESOURCE *my_res = (MYSQLI_RESOURCE *)intern->ptr;
if (my_res && my_res->ptr) {
@ -239,7 +227,7 @@ static void mysqli_link_free_storage(void *object TSRMLS_DC)
/* }}} */
/* {{{ mysql_driver_free_storage */
static void mysqli_driver_free_storage(void *object TSRMLS_DC)
static void mysqli_driver_free_storage(zend_object *object TSRMLS_DC)
{
mysqli_objects_free_storage(object TSRMLS_CC);
}
@ -247,10 +235,9 @@ static void mysqli_driver_free_storage(void *object TSRMLS_DC)
/* {{{ mysqli_stmt_free_storage
*/
static void mysqli_stmt_free_storage(void *object TSRMLS_DC)
static void mysqli_stmt_free_storage(zend_object *object TSRMLS_DC)
{
zend_object *zo = (zend_object *)object;
mysqli_object *intern = (mysqli_object *)zo;
mysqli_object *intern = php_mysqli_fetch_object(object);
MYSQLI_RESOURCE *my_res = (MYSQLI_RESOURCE *)intern->ptr;
if (my_res && my_res->ptr) {
@ -263,10 +250,9 @@ static void mysqli_stmt_free_storage(void *object TSRMLS_DC)
/* {{{ mysqli_result_free_storage
*/
static void mysqli_result_free_storage(void *object TSRMLS_DC)
static void mysqli_result_free_storage(zend_object *object TSRMLS_DC)
{
zend_object *zo = (zend_object *)object;
mysqli_object *intern = (mysqli_object *)zo;
mysqli_object *intern = php_mysqli_fetch_object(object);
MYSQLI_RESOURCE *my_res = (MYSQLI_RESOURCE *)intern->ptr;
if (my_res && my_res->ptr) {
@ -278,10 +264,9 @@ static void mysqli_result_free_storage(void *object TSRMLS_DC)
/* {{{ mysqli_warning_free_storage
*/
static void mysqli_warning_free_storage(void *object TSRMLS_DC)
static void mysqli_warning_free_storage(zend_object *object TSRMLS_DC)
{
zend_object *zo = (zend_object *)object;
mysqli_object *intern = (mysqli_object *)zo;
mysqli_object *intern = php_mysqli_fetch_object(object);
MYSQLI_RESOURCE *my_res = (MYSQLI_RESOURCE *)intern->ptr;
if (my_res && my_res->ptr) {
@ -293,11 +278,10 @@ static void mysqli_warning_free_storage(void *object TSRMLS_DC)
/* }}} */
/* {{{ mysqli_read_na */
static int mysqli_read_na(mysqli_object *obj, zval **retval TSRMLS_DC)
static zval *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;
return NULL;
}
/* }}} */
@ -309,87 +293,73 @@ static int mysqli_write_na(mysqli_object *obj, zval *newval TSRMLS_DC)
}
/* }}} */
#ifndef Z_ADDREF_P
/* PHP 5.2, old GC */
#define Z_ADDREF_P(pz) (++(pz)->refcount)
#define Z_REFCOUNT_P(pz) ((pz)->refcount)
#define Z_SET_REFCOUNT_P(pz, rc) ((pz)->refcount = rc)
#endif
/* {{{ mysqli_read_property */
zval *mysqli_read_property(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC)
zval *mysqli_read_property(zval *object, zval *member, int type, zend_uint cache_slot, zval *rv TSRMLS_DC)
{
zval tmp_member;
zval *retval;
mysqli_object *obj;
mysqli_prop_handler *hnd;
int ret;
mysqli_prop_handler *hnd = NULL;
ret = FAILURE;
obj = (mysqli_object *)zend_objects_get_address(object TSRMLS_CC);
obj = Z_MYSQLI_P(object);
if (member->type != IS_STRING) {
tmp_member = *member;
zval_copy_ctor(&tmp_member);
if (Z_TYPE_P(member) != IS_STRING) {
ZVAL_DUP(&tmp_member, 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);
hnd = zend_hash_find_ptr(obj->prop_handler, Z_STR_P(member));
}
if (ret == SUCCESS) {
ret = hnd->read_func(obj, &retval TSRMLS_CC);
if (ret == SUCCESS) {
/* ensure we're creating a temporary variable */
Z_SET_REFCOUNT_P(retval, 0);
} else {
retval = EG(uninitialized_zval_ptr);
if (hnd) {
retval = hnd->read_func(obj, rv TSRMLS_CC);
if (retval == NULL) {
retval = &EG(uninitialized_zval);
}
} else {
zend_object_handlers * std_hnd = zend_get_std_object_handlers();
retval = std_hnd->read_property(object, member, type, key TSRMLS_CC);
zend_object_handlers *std_hnd = zend_get_std_object_handlers();
retval = std_hnd->read_property(object, member, type, cache_slot, rv TSRMLS_CC);
}
if (member == &tmp_member) {
zval_dtor(member);
}
return(retval);
return retval;
}
/* }}} */
/* {{{ mysqli_write_property */
void mysqli_write_property(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC)
void mysqli_write_property(zval *object, zval *member, zval *value, zend_uint cache_slot TSRMLS_DC)
{
zval tmp_member;
mysqli_object *obj;
mysqli_prop_handler *hnd;
int ret;
mysqli_prop_handler *hnd = NULL;
if (member->type != IS_STRING) {
tmp_member = *member;
zval_copy_ctor(&tmp_member);
if (Z_TYPE_P(member) != IS_STRING) {
ZVAL_DUP(&tmp_member, member);
convert_to_string(&tmp_member);
member = &tmp_member;
}
ret = FAILURE;
obj = (mysqli_object *)zend_objects_get_address(object TSRMLS_CC);
obj = Z_MYSQLI_P(object);
if (obj->prop_handler != NULL) {
ret = zend_hash_find((HashTable *)obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
hnd = zend_hash_find_ptr(obj->prop_handler, Z_STR_P(member));
}
if (ret == SUCCESS) {
if (hnd) {
hnd->write_func(obj, value TSRMLS_CC);
/* ???
if (! PZVAL_IS_REF(value) && Z_REFCOUNT_P(value) == 0) {
Z_ADDREF_P(value);
zval_ptr_dtor(&value);
}
} */
} else {
zend_object_handlers * std_hnd = zend_get_std_object_handlers();
std_hnd->write_property(object, member, value, key TSRMLS_CC);
zend_object_handlers *std_hnd = zend_get_std_object_handlers();
std_hnd->write_property(object, member, value, cache_slot TSRMLS_CC);
}
if (member == &tmp_member) {
@ -400,45 +370,42 @@ void mysqli_write_property(zval *object, zval *member, zval *value, const zend_l
/* {{{ void mysqli_add_property(HashTable *h, char *pname, mysqli_read_t r_func, mysqli_write_t w_func TSRMLS_DC) */
void mysqli_add_property(HashTable *h, const char *pname, size_t pname_len, mysqli_read_t r_func, mysqli_write_t w_func TSRMLS_DC) {
mysqli_prop_handler p;
mysqli_prop_handler p;
p.name = (char*) pname;
p.name_len = pname_len;
p.name = STR_INIT(pname, pname_len, 1);
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, pname_len + 1, &p, sizeof(mysqli_prop_handler), NULL);
zend_hash_add_mem(h, p.name, &p, sizeof(mysqli_prop_handler));
STR_RELEASE(p.name);
}
/* }}} */
static int mysqli_object_has_property(zval *object, zval *member, int has_set_exists, const zend_literal *key TSRMLS_DC) /* {{{ */
static int mysqli_object_has_property(zval *object, zval *member, int has_set_exists, zend_uint cache_slot TSRMLS_DC) /* {{{ */
{
mysqli_object *obj = (mysqli_object *)zend_objects_get_address(object TSRMLS_CC);
mysqli_prop_handler p;
mysqli_object *obj = Z_MYSQLI_P(object);
mysqli_prop_handler *p;
int ret = 0;
if (zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member) + 1, (void **)&p) == SUCCESS) {
if ((p = zend_hash_find_ptr(obj->prop_handler, Z_STR_P(member))) != NULL) {
switch (has_set_exists) {
case 2:
ret = 1;
break;
case 1: {
zval *value = mysqli_read_property(object, member, BP_VAR_IS, key TSRMLS_CC);
if (value != EG(uninitialized_zval_ptr)) {
zval rv;
zval *value = mysqli_read_property(object, member, BP_VAR_IS, cache_slot, &rv TSRMLS_CC);
if (value != &EG(uninitialized_zval)) {
convert_to_boolean(value);
ret = Z_TYPE_P(value) == IS_TRUE ? 1 : 0;
/* refcount is 0 */
Z_ADDREF_P(value);
zval_ptr_dtor(&value);
}
break;
}
case 0:{
zval *value = mysqli_read_property(object, member, BP_VAR_IS, key TSRMLS_CC);
if (value != EG(uninitialized_zval_ptr)) {
ret = Z_TYPE_P(value) != IS_NULL? 1:0;
/* refcount is 0 */
Z_ADDREF_P(value);
zval_ptr_dtor(&value);
zval rv;
zval *value = mysqli_read_property(object, member, BP_VAR_IS, cache_slot, &rv TSRMLS_CC);
if (value != &EG(uninitialized_zval)) {
ret = Z_TYPE_P(value) != IS_NULL? 1 : 0;
zval_ptr_dtor(value);
}
break;
}
@ -446,17 +413,16 @@ static int mysqli_object_has_property(zval *object, zval *member, int has_set_ex
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid value for has_set_exists");
}
} else {
zend_object_handlers * std_hnd = zend_get_std_object_handlers();
ret = std_hnd->has_property(object, member, has_set_exists, key TSRMLS_CC);
zend_object_handlers *std_hnd = zend_get_std_object_handlers();
ret = std_hnd->has_property(object, member, has_set_exists, cache_slot TSRMLS_CC);
}
return ret;
} /* }}} */
#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3
HashTable * mysqli_object_get_debug_info(zval *object, int *is_temp TSRMLS_DC)
HashTable *mysqli_object_get_debug_info(zval *object, int *is_temp TSRMLS_DC)
{
mysqli_object *obj = (mysqli_object *)zend_objects_get_address(object TSRMLS_CC);
mysqli_object *obj = Z_MYSQLI_P(object);
HashTable *retval, *props = obj->prop_handler;
HashPosition pos;
mysqli_prop_handler *entry;
@ -464,69 +430,61 @@ HashTable * mysqli_object_get_debug_info(zval *object, int *is_temp TSRMLS_DC)
ALLOC_HASHTABLE(retval);
ZEND_INIT_SYMTABLE_EX(retval, zend_hash_num_elements(props) + 1, 0);
zend_hash_internal_pointer_reset_ex(props, &pos);
while (zend_hash_get_current_data_ex(props, (void **)&entry, &pos) == SUCCESS) {
zval member;
ZEND_HASH_FOREACH_PTR(props, entry) {
zval rv, member;
zval *value;
INIT_ZVAL(member);
ZVAL_STRINGL(&member, entry->name, entry->name_len, 0);
value = mysqli_read_property(object, &member, BP_VAR_IS, 0 TSRMLS_CC);
if (value != EG(uninitialized_zval_ptr)) {
Z_ADDREF_P(value);
zend_hash_add(retval, entry->name, entry->name_len + 1, &value, sizeof(zval *), NULL);
ZVAL_STR(&member, entry->name);
value = mysqli_read_property(object, &member, BP_VAR_IS, 0, &rv TSRMLS_CC);
if (value != &EG(uninitialized_zval)) {
if (Z_REFCOUNTED_P(value)) {
Z_ADDREF_P(value);
}
zend_hash_add(retval, Z_STR(member), value);
}
zend_hash_move_forward_ex(props, &pos);
}
} ZEND_HASH_FOREACH_END();
*is_temp = 1;
return retval;
}
#endif
/* {{{ mysqli_objects_new
*/
PHP_MYSQLI_EXPORT(zend_object_value) mysqli_objects_new(zend_class_entry *class_type TSRMLS_DC)
PHP_MYSQLI_EXPORT(zend_object *) mysqli_objects_new(zend_class_entry *class_type TSRMLS_DC)
{
zend_object_value retval;
mysqli_object *intern;
zend_class_entry *mysqli_base_class;
zend_objects_free_object_storage_t free_storage;
zend_object_handlers *handlers;
intern = emalloc(sizeof(mysqli_object));
memset(intern, 0, sizeof(mysqli_object));
intern->ptr = NULL;
intern->prop_handler = NULL;
intern = ecalloc(1, sizeof(mysqli_object) + sizeof(zval) * (class_type->default_properties_count - 1));
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);
intern->prop_handler = zend_hash_find_ptr(&classes, mysqli_base_class->name);
zend_object_std_init(&intern->zo, class_type TSRMLS_CC);
object_properties_init(&intern->zo, class_type);
/* link object */
if (instanceof_function(class_type, mysqli_link_class_entry TSRMLS_CC)) {
free_storage = mysqli_link_free_storage;
handlers = &mysqli_object_link_handlers;
} else if (instanceof_function(class_type, mysqli_driver_class_entry TSRMLS_CC)) { /* driver object */
free_storage = mysqli_driver_free_storage;
handlers = &mysqli_object_driver_handlers;
} else if (instanceof_function(class_type, mysqli_stmt_class_entry TSRMLS_CC)) { /* stmt object */
free_storage = mysqli_stmt_free_storage;
handlers = &mysqli_object_stmt_handlers;
} else if (instanceof_function(class_type, mysqli_result_class_entry TSRMLS_CC)) { /* result object */
free_storage = mysqli_result_free_storage;
handlers = &mysqli_object_result_handlers;
} else if (instanceof_function(class_type, mysqli_warning_class_entry TSRMLS_CC)) { /* warning object */
free_storage = mysqli_warning_free_storage;
handlers = &mysqli_object_warning_handlers;
} else {
free_storage = mysqli_objects_free_storage;
handlers = &mysqli_object_handlers;
}
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;
intern->zo.handlers = &mysqli_object_handlers;
return retval;
return &intern->zo;
}
/* }}} */
@ -535,9 +493,9 @@ PHP_MYSQLI_EXPORT(zend_object_value) mysqli_objects_new(zend_class_entry *class_
static MYSQLND *mysqli_convert_zv_to_mysqlnd(zval * zv TSRMLS_DC)
{
if (Z_TYPE_P(zv) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zv), mysqli_link_class_entry TSRMLS_CC)) {
MY_MYSQL * mysql;
MYSQLI_RESOURCE * my_res;
mysqli_object * intern = (mysqli_object *)zend_object_store_get_object(zv TSRMLS_CC);
MY_MYSQL *mysql;
MYSQLI_RESOURCE *my_res;
mysqli_object *intern = Z_MYSQLI_P(zv);
if (!(my_res = (MYSQLI_RESOURCE *)intern->ptr)) {
/* We know that we have a mysqli object, so this failure should be emitted */
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", intern->zo.ce->name);
@ -576,7 +534,6 @@ PHP_INI_BEGIN()
PHP_INI_END()
/* }}} */
/* {{{ PHP_GINIT_FUNCTION
*/
static PHP_GINIT_FUNCTION(mysqli)
@ -622,6 +579,8 @@ PHP_MINIT_FUNCTION(mysqli)
#endif
memcpy(&mysqli_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
mysqli_object_handlers.offset = XtOffsetOf(mysqli_object, zo);
mysqli_object_handlers.free_obj = mysqli_objects_free_storage;
mysqli_object_handlers.clone_obj = NULL;
mysqli_object_handlers.read_property = mysqli_read_property;
mysqli_object_handlers.write_property = mysqli_write_property;
@ -630,6 +589,16 @@ PHP_MINIT_FUNCTION(mysqli)
#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3
mysqli_object_handlers.get_debug_info = mysqli_object_get_debug_info;
#endif
memcpy(&mysqli_object_driver_handlers, &mysqli_object_handlers, sizeof(zend_object_handlers));
mysqli_object_driver_handlers.free_obj = mysqli_driver_free_storage;
memcpy(&mysqli_object_link_handlers, &mysqli_object_handlers, sizeof(zend_object_handlers));
mysqli_object_link_handlers.free_obj = mysqli_link_free_storage;
memcpy(&mysqli_object_result_handlers, &mysqli_object_handlers, sizeof(zend_object_handlers));
mysqli_object_result_handlers.free_obj = mysqli_result_free_storage;
memcpy(&mysqli_object_stmt_handlers, &mysqli_object_handlers, sizeof(zend_object_handlers));
mysqli_object_stmt_handlers.free_obj = mysqli_stmt_free_storage;
memcpy(&mysqli_object_warning_handlers, &mysqli_object_handlers, sizeof(zend_object_handlers));
mysqli_object_warning_handlers.free_obj = mysqli_warning_free_storage;
zend_hash_init(&classes, 0, NULL, NULL, 1);
@ -651,41 +620,79 @@ PHP_MINIT_FUNCTION(mysqli)
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);
MYSQLI_ADD_PROPERTIES_INFO(ce, mysqli_driver_property_info_entries);
zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_driver_properties, sizeof(mysqli_driver_properties), NULL);
zend_declare_property_null(ce, "client_info", sizeof("client_info") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "client_version", sizeof("client_version") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "driver_version", sizeof("driver_version") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "embedded", sizeof("embedded") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "reconnect", sizeof("reconnect") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "report_mode", sizeof("report_mode") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
zend_hash_add_ptr(&classes, ce->name, &mysqli_driver_properties);
REGISTER_MYSQLI_CLASS_ENTRY("mysqli", mysqli_link_class_entry, mysqli_link_methods);
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);
MYSQLI_ADD_PROPERTIES_INFO(ce, mysqli_link_property_info_entries);
zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_link_properties, sizeof(mysqli_link_properties), NULL);
zend_declare_property_null(ce, "affected_rows", sizeof("affected_rows") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "client_info", sizeof("client_info") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "client_version", sizeof("client_version") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "connect_errno", sizeof("connect_errno") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "connect_error", sizeof("connect_error") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "errno", sizeof("errno") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "error", sizeof("error") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "error_list", sizeof("error_list") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "field_count", sizeof("field_count") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "host_info", sizeof("host_info") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "info", sizeof("info") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "insert_id", sizeof("insert_id") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "server_info", sizeof("server_info") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "server_version", sizeof("server_version") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "stat", sizeof("stat") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "sqlstate", sizeof("sqlstate") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "protocol_version", sizeof("protocol_version") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "thread_id", sizeof("thread_id") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "warning_count", sizeof("warning_count") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_hash_add_ptr(&classes, ce->name, &mysqli_link_properties);
REGISTER_MYSQLI_CLASS_ENTRY("mysqli_warning", mysqli_warning_class_entry, mysqli_warning_methods);
ce = mysqli_warning_class_entry;
ce->ce_flags |= ZEND_ACC_FINAL_CLASS | ZEND_ACC_PROTECTED;
zend_hash_init(&mysqli_warning_properties, 0, NULL, NULL, 1);
MYSQLI_ADD_PROPERTIES(&mysqli_warning_properties, mysqli_warning_property_entries);
MYSQLI_ADD_PROPERTIES_INFO(ce, mysqli_warning_property_info_entries);
zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_warning_properties, sizeof(mysqli_warning_properties), NULL);
zend_declare_property_null(ce, "message", sizeof("message") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "sqlstate", sizeof("sqlstate") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "errno", sizeof("errno") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_hash_add_ptr(&classes, ce->name, &mysqli_warning_properties);
REGISTER_MYSQLI_CLASS_ENTRY("mysqli_result", mysqli_result_class_entry, mysqli_result_methods);
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);
MYSQLI_ADD_PROPERTIES_INFO(ce, mysqli_result_property_info_entries);
zend_declare_property_null(ce, "current_field", sizeof("current_field") - 1,ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "field_count", sizeof("field_count") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "lengths", sizeof("lengths") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "num_rows", sizeof("num_rows") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "type", sizeof("type") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
mysqli_result_class_entry->get_iterator = php_mysqli_result_get_iterator;
mysqli_result_class_entry->iterator_funcs.funcs = &php_mysqli_result_iterator_funcs;
zend_class_implements(mysqli_result_class_entry TSRMLS_CC, 1, zend_ce_traversable);
zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_result_properties, sizeof(mysqli_result_properties), NULL);
zend_hash_add_ptr(&classes, ce->name, &mysqli_result_properties);
REGISTER_MYSQLI_CLASS_ENTRY("mysqli_stmt", mysqli_stmt_class_entry, mysqli_stmt_methods);
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);
MYSQLI_ADD_PROPERTIES_INFO(ce, mysqli_stmt_property_info_entries);
zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_stmt_properties, sizeof(mysqli_stmt_properties), NULL);
zend_declare_property_null(ce, "affected_rows", sizeof("affected_rows") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "insert_id", sizeof("insert_id") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "num_rows", sizeof("num_rows") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "param_count", sizeof("param_count") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "field_count", sizeof("field_count") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "errno", sizeof("errno") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "error", sizeof("error") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "error_list", sizeof("error_list") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "sqlstate", sizeof("sqlstate") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(ce, "id", sizeof("id") - 1, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_hash_add_ptr(&classes, ce->name, &mysqli_stmt_properties);
/* mysqli_options */
REGISTER_LONG_CONSTANT("MYSQLI_READ_DEFAULT_GROUP", MYSQL_READ_DEFAULT_GROUP, CONST_CS | CONST_PERSISTENT);
@ -1048,7 +1055,7 @@ PHP_FUNCTION(mysqli_stmt_construct)
if (zend_parse_parameters(1 TSRMLS_CC, "O", &mysql_link, mysqli_link_class_entry)==FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
stmt = (MY_STMT *)ecalloc(1,sizeof(MY_STMT));
@ -1058,7 +1065,7 @@ PHP_FUNCTION(mysqli_stmt_construct)
if (zend_parse_parameters(2 TSRMLS_CC, "Os", &mysql_link, mysqli_link_class_entry, &statement, &statement_len)==FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
stmt = (MY_STMT *)ecalloc(1,sizeof(MY_STMT));
@ -1076,15 +1083,14 @@ PHP_FUNCTION(mysqli_stmt_construct)
RETURN_FALSE;
}
#ifndef MYSQLI_USE_MYSQLND
stmt->link_handle = Z_OBJ_HANDLE(*mysql_link);
zend_objects_store_add_ref_by_handle(stmt->link_handle TSRMLS_CC);
ZVAL_COPY(&stmt->link_handle, mysql_link);
#endif
mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
mysqli_resource->ptr = (void *)stmt;
mysqli_resource->status = (ZEND_NUM_ARGS() == 1) ? MYSQLI_STATUS_INITIALIZED : MYSQLI_STATUS_VALID;
((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->ptr = mysqli_resource;
MYSQLI_REGISTER_RESOURCE_EX(mysqli_resource, getThis());
}
/* }}} */
@ -1116,7 +1122,7 @@ PHP_FUNCTION(mysqli_result_construct)
WRONG_PARAM_COUNT;
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
switch (resmode) {
case MYSQLI_STORE_RESULT:
@ -1137,12 +1143,10 @@ PHP_FUNCTION(mysqli_result_construct)
mysqli_resource->ptr = (void *)result;
mysqli_resource->status = MYSQLI_STATUS_VALID;
((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->ptr = mysqli_resource;
MYSQLI_REGISTER_RESOURCE_EX(mysqli_resource, getThis());
}
/* }}} */
/* {{{ php_mysqli_fetch_into_hash_aux
*/
void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * result, long fetchtype TSRMLS_DC)
@ -1166,9 +1170,7 @@ void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * result, long
for (i = 0; i < mysql_num_fields(result); i++) {
if (row[i]) {
zval *res;
MAKE_STD_ZVAL(res);
zval res;
#if MYSQL_VERSION_ID > 50002
if (mysql_fetch_field_direct(result, i)->type == MYSQL_TYPE_BIT) {
@ -1189,7 +1191,7 @@ void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * result, long
* 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);
ZVAL_STRING(&res, tmp);
} else
#endif
{
@ -1197,24 +1199,23 @@ void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * result, long
#if PHP_API_VERSION < 20100412
/* check if we need magic quotes */
if (PG(magic_quotes_runtime)) {
Z_TYPE_P(res) = IS_STRING;
Z_STRVAL_P(res) = php_addslashes(row[i], field_len[i], &Z_STRLEN_P(res), 0 TSRMLS_CC);
ZVAL_STR(&res, php_addslashes(row[i], field_len[i], 0 TSRMLS_CC));
} else {
#endif
ZVAL_STRINGL(res, row[i], field_len[i], 1);
ZVAL_STRINGL(&res, row[i], field_len[i]);
#if PHP_API_VERSION < 20100412
}
#endif
}
if (fetchtype & MYSQLI_NUM) {
add_index_zval(return_value, i, res);
add_index_zval(return_value, i, &res);
}
if (fetchtype & MYSQLI_ASSOC) {
if (fetchtype & MYSQLI_NUM) {
Z_ADDREF_P(res);
if (fetchtype & MYSQLI_NUM && Z_REFCOUNTED(res)) {
Z_ADDREF(res);
}
add_assoc_zval(return_value, fields[i].name, res);
add_assoc_zval(return_value, fields[i].name, &res);
}
} else {
if (fetchtype & MYSQLI_NUM) {
@ -1231,7 +1232,6 @@ void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * result, long
}
/* }}} */
/* {{{ php_mysqli_fetch_into_hash
*/
void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags, int into_object)
@ -1243,16 +1243,15 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
zend_class_entry *ce = NULL;
if (into_object) {
char *class_name;
int class_name_len;
zend_string *class_name = NULL;
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) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|Sz", &mysql_result, mysqli_result_class_entry, &class_name, &ctor_params) == FAILURE) {
return;
}
if (ZEND_NUM_ARGS() < (getThis() ? 1 : 2)) {
if (class_name) {
ce = zend_standard_class_def;
} else {
ce = zend_fetch_class(class_name, class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
ce = zend_fetch_class(class_name, ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
}
if (!ce) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not find class '%s'", class_name);
@ -1272,7 +1271,7 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
}
}
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
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");
@ -1282,10 +1281,11 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
php_mysqli_fetch_into_hash_aux(return_value, result, fetchtype TSRMLS_CC);
if (into_object && Z_TYPE_P(return_value) == IS_ARRAY) {
zval dataset = *return_value;
zval dataset, retval;
zend_fcall_info fci;
zend_fcall_info_cache fcc;
zval *retval_ptr;
ZVAL_COPY_VALUE(&dataset, return_value);
object_and_properties_init(return_value, ce, NULL);
zend_merge_properties(return_value, Z_ARRVAL(dataset), 1 TSRMLS_CC);
@ -1293,10 +1293,10 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
if (ce->constructor) {
fci.size = sizeof(fci);
fci.function_table = &ce->function_table;
fci.function_name = NULL;
ZVAL_UNDEF(&fci.function_name);
fci.symbol_table = NULL;
fci.object_ptr = return_value;
fci.retval_ptr_ptr = &retval_ptr;
fci.object = Z_OBJ_P(return_value);
fci.retval = &retval;
fci.params = NULL;
fci.param_count = 0;
fci.no_separation = 1;
@ -1318,14 +1318,12 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
fcc.function_handler = ce->constructor;
fcc.calling_scope = EG(scope);
fcc.called_scope = Z_OBJCE_P(return_value);
fcc.object_ptr = return_value;
fcc.object = Z_OBJ_P(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);
}
zval_ptr_dtor(&retval);
}
if (fci.params) {
efree(fci.params);

File diff suppressed because it is too large Load Diff

View File

@ -30,11 +30,10 @@
#include "mysqli_fe.h"
#define MAP_PROPERTY_MYG_BOOL_READ(name, value) \
static int name(mysqli_object *obj, zval **retval TSRMLS_DC) \
static zval *name(mysqli_object *obj, zval *retval TSRMLS_DC) \
{ \
MAKE_STD_ZVAL(*retval); \
ZVAL_BOOL(*retval, MyG(value)); \
return SUCCESS; \
ZVAL_BOOL(retval, MyG(value)); \
return retval; \
} \
#define MAP_PROPERTY_MYG_BOOL_WRITE(name, value) \
@ -45,11 +44,10 @@ static int name(mysqli_object *obj, zval *value TSRMLS_DC) \
} \
#define MAP_PROPERTY_MYG_LONG_READ(name, value) \
static int name(mysqli_object *obj, zval **retval TSRMLS_DC) \
static zval *name(mysqli_object *obj, zval *retval TSRMLS_DC) \
{ \
MAKE_STD_ZVAL(*retval); \
ZVAL_LONG(*retval, MyG(value)); \
return SUCCESS; \
ZVAL_LONG(retval, MyG(value)); \
return retval; \
} \
#define MAP_PROPERTY_MYG_LONG_WRITE(name, value) \
@ -60,11 +58,10 @@ static int name(mysqli_object *obj, zval *value TSRMLS_DC) \
} \
#define MAP_PROPERTY_MYG_STRING_READ(name, value) \
static int name(mysqli_object *obj, zval **retval TSRMLS_DC) \
static zval *name(mysqli_object *obj, zval *retval TSRMLS_DC) \
{ \
MAKE_STD_ZVAL(*retval); \
ZVAL_STRING(*retval, MyG(value), 1); \
return SUCCESS; \
ZVAL_STRING(retval, MyG(value)); \
return retval; \
} \
#define MAP_PROPERTY_MYG_STRING_WRITE(name, value) \
@ -85,42 +82,38 @@ static int driver_report_write(mysqli_object *obj, zval *value TSRMLS_DC)
/* }}} */
/* {{{ property driver_embedded_read */
static int driver_embedded_read(mysqli_object *obj, zval **retval TSRMLS_DC)
static zval *driver_embedded_read(mysqli_object *obj, zval *retval TSRMLS_DC)
{
MAKE_STD_ZVAL(*retval);
#ifdef HAVE_EMBEDDED_MYSQLI
ZVAL_BOOL(*retval, 1);
ZVAL_BOOL(retval, 1);
#else
ZVAL_BOOL(*retval, 0);
ZVAL_BOOL(retval, 0);
#endif
return SUCCESS;
return retval;
}
/* }}} */
/* {{{ property driver_client_version_read */
static int driver_client_version_read(mysqli_object *obj, zval **retval TSRMLS_DC)
static zval *driver_client_version_read(mysqli_object *obj, zval *retval TSRMLS_DC)
{
MAKE_STD_ZVAL(*retval);
ZVAL_LONG(*retval, MYSQL_VERSION_ID);
return SUCCESS;
ZVAL_LONG(retval, MYSQL_VERSION_ID);
return retval;
}
/* }}} */
/* {{{ property driver_client_info_read */
static int driver_client_info_read(mysqli_object *obj, zval **retval TSRMLS_DC)
static zval *driver_client_info_read(mysqli_object *obj, zval *retval TSRMLS_DC)
{
MAKE_STD_ZVAL(*retval);
ZVAL_STRING(*retval, (char *)mysql_get_client_info(), 1);
return SUCCESS;
ZVAL_STRING(retval, (char *)mysql_get_client_info());
return retval;
}
/* }}} */
/* {{{ property driver_driver_version_read */
static int driver_driver_version_read(mysqli_object *obj, zval **retval TSRMLS_DC)
static zval *driver_driver_version_read(mysqli_object *obj, zval *retval TSRMLS_DC)
{
MAKE_STD_ZVAL(*retval);
ZVAL_LONG(*retval, MYSQLI_VERSION_ID);
return SUCCESS;
ZVAL_LONG(retval, MYSQLI_VERSION_ID);
return retval;
}
/* }}} */
@ -136,7 +129,7 @@ ZEND_FUNCTION(mysqli_driver_construct)
mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
mysqli_resource->ptr = 1;
mysqli_resource->status = (ZEND_NUM_ARGS() == 1) ? MYSQLI_STATUS_INITIALIZED : MYSQLI_STATUS_VALID;
((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->ptr = mysqli_resource;
(Z_MYSQLI_P(getThis()))->ptr = mysqli_resource;
#endif
}
@ -150,19 +143,6 @@ const mysqli_property_entry mysqli_driver_property_entries[] = {
{NULL, 0, NULL, NULL}
};
/* {{{ mysqli_warning_property_info_entries */
const zend_property_info mysqli_driver_property_info_entries[] = {
{ZEND_ACC_PUBLIC, "client_info", sizeof("client_info") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "client_version", sizeof("client_version") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "driver_version", sizeof("driver_version") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "embedded", sizeof("embedded") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "reconnect", sizeof("reconnect") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "report_mode", sizeof("report_mode") - 1, -1, 0, NULL, 0, NULL},
{0, NULL, 0, -1, 0, NULL, 0, NULL},
};
/* }}} */
/* {{{ mysqli_driver_methods[]
*/
const zend_function_entry mysqli_driver_methods[] = {

View File

@ -38,7 +38,7 @@ const zend_function_entry mysqli_exception_methods[] = {
void php_mysqli_throw_sql_exception(char *sqlstate, int errorno TSRMLS_DC, char *format, ...)
{
zval *sql_ex;
zval sql_ex;
va_list arg;
char *message;
@ -52,26 +52,25 @@ void php_mysqli_throw_sql_exception(char *sqlstate, int errorno TSRMLS_DC, char
return;
}
MAKE_STD_ZVAL(sql_ex);
object_init_ex(sql_ex, mysqli_exception_class_entry);
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,
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,
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,
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_update_property_long(mysqli_exception_class_entry, &sql_ex, "code", sizeof("code") - 1, errorno TSRMLS_CC);
zend_throw_exception_object(sql_ex TSRMLS_CC);
zend_throw_exception_object(&sql_ex TSRMLS_CC);
}
/*

View File

@ -56,8 +56,7 @@ static void php_mysqli_set_error(long mysql_errno, char *mysql_err TSRMLS_DC)
}
/* }}} */
void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_connect, zend_bool in_ctor)
void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_connect, zend_bool in_ctor) /* {{{ */
{
MY_MYSQL *mysql = NULL;
MYSQLI_RESOURCE *mysqli_resource = NULL;
@ -66,10 +65,9 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
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_string *hash_key = NULL;
zend_bool new_connection = FALSE;
zend_rsrc_list_entry *le;
zend_resource *le;
mysqli_plist_entry *plist = NULL;
zend_bool self_alloced = 0;
@ -95,7 +93,7 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
}
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;
mysqli_resource = (Z_MYSQLI_P(object))->ptr;
if (mysqli_resource && mysqli_resource->ptr) {
mysql = (MY_MYSQL*) mysqli_resource->ptr;
}
@ -113,8 +111,8 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
return;
}
mysqli_resource = ((mysqli_object *) zend_object_store_get_object(object TSRMLS_CC))->ptr;
MYSQLI_FETCH_RESOURCE_CONN(mysql, &object, MYSQLI_STATUS_INITIALIZED);
mysqli_resource = (Z_MYSQLI_P(object))->ptr;
MYSQLI_FETCH_RESOURCE_CONN(mysql, object, MYSQLI_STATUS_INITIALIZED);
/* set some required options */
flags |= CLIENT_MULTI_RESULTS; /* needed for mysql_multi_query() */
@ -156,15 +154,15 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
} else {
mysql->persistent = persistent = TRUE;
hash_len = spprintf(&hash_key, 0, "mysqli_%s_%s%ld%s%s%s", SAFE_STR(hostname), SAFE_STR(socket),
hash_key = strpprintf(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()) {
if ((le = zend_hash_find_ptr(&EG(persistent_list), hash_key)) != NULL) {
if (le->type == php_le_pmysqli()) {
plist = (mysqli_plist_entry *) le->ptr;
do {
@ -192,12 +190,12 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
} while (0);
}
} else {
zend_rsrc_list_entry le;
zend_resource 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);
zend_hash_update_mem(&EG(persistent_list), hash_key, &le, sizeof(le));
}
}
}
@ -283,7 +281,7 @@ end:
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;
(Z_MYSQLI_P(object))->ptr = mysqli_resource;
}
if (!is_real_connect) {
return;
@ -293,7 +291,7 @@ end:
err:
if (mysql->hash_key) {
efree(mysql->hash_key);
STR_RELEASE(mysql->hash_key);
mysql->hash_key = NULL;
mysql->persistent = FALSE;
}
@ -301,8 +299,7 @@ err:
efree(mysql);
}
RETVAL_FALSE;
}
} /* }}} */
/* {{{ proto object mysqli_connect([string hostname [,string username [,string passwd [,string dbname [,int port [,string socket]]]]]])
Open a connection to a mysql server */
@ -312,7 +309,6 @@ PHP_FUNCTION(mysqli_connect)
}
/* }}} */
/* {{{ proto object mysqli_link_construct()
*/
PHP_FUNCTION(mysqli_link_construct)
@ -321,7 +317,6 @@ PHP_FUNCTION(mysqli_link_construct)
}
/* }}} */
/* {{{ proto int mysqli_connect_errno(void)
Returns the numerical value of the error message from last connect command */
PHP_FUNCTION(mysqli_connect_errno)
@ -335,14 +330,13 @@ PHP_FUNCTION(mysqli_connect_errno)
PHP_FUNCTION(mysqli_connect_error)
{
if (MyG(error_msg)) {
RETURN_STRING(MyG(error_msg),1);
RETURN_STRING(MyG(error_msg));
} else {
RETURN_NULL();
}
}
/* }}} */
/* {{{ proto mixed mysqli_fetch_array (object result [,int resulttype])
Fetch a result row as an associative array, a numeric array, or both */
PHP_FUNCTION(mysqli_fetch_array)
@ -359,7 +353,6 @@ PHP_FUNCTION(mysqli_fetch_assoc)
}
/* }}} */
/* {{{ proto mixed mysqli_fetch_all (object result [,int resulttype])
Fetches all result rows as an associative array, a numeric array, or both */
#if defined(MYSQLI_USE_MYSQLND)
@ -384,8 +377,6 @@ PHP_FUNCTION(mysqli_fetch_all)
}
/* }}} */
/* {{{ proto array mysqli_get_client_stats(void)
Returns statistics about the zval cache */
PHP_FUNCTION(mysqli_get_client_stats)
@ -397,7 +388,6 @@ PHP_FUNCTION(mysqli_get_client_stats)
}
/* }}} */
/* {{{ proto array mysqli_get_connection_stats(void)
Returns statistics about the zval cache */
PHP_FUNCTION(mysqli_get_connection_stats)
@ -426,7 +416,7 @@ PHP_FUNCTION(mysqli_error_list)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
array_init(return_value);
#if defined(MYSQLI_USE_MYSQLND)
if (mysql->mysql->data->error_info->error_list) {
@ -436,30 +426,27 @@ PHP_FUNCTION(mysqli_error_list)
message;
message = (MYSQLND_ERROR_LIST_ELEMENT *) zend_llist_get_next_ex(mysql->mysql->data->error_info->error_list, &pos))
{
zval * single_error;
MAKE_STD_ZVAL(single_error);
array_init(single_error);
add_assoc_long_ex(single_error, "errno", sizeof("errno"), message->error_no);
add_assoc_string_ex(single_error, "sqlstate", sizeof("sqlstate"), message->sqlstate);
add_assoc_string_ex(single_error, "error", sizeof("error"), message->error);
add_next_index_zval(return_value, single_error);
zval single_error;
array_init(&single_error);
add_assoc_long_ex(&single_error, "errno", sizeof("errno") - 1, message->error_no);
add_assoc_string_ex(&single_error, "sqlstate", sizeof("sqlstate") - 1, message->sqlstate);
add_assoc_string_ex(&single_error, "error", sizeof("error") - 1, message->error);
add_next_index_zval(return_value, &single_error);
}
}
#else
if (mysql_errno(mysql->mysql)) {
zval * single_error;
MAKE_STD_ZVAL(single_error);
array_init(single_error);
add_assoc_long_ex(single_error, "errno", sizeof("errno"), mysql_errno(mysql->mysql));
add_assoc_string_ex(single_error, "sqlstate", sizeof("sqlstate"), mysql_sqlstate(mysql->mysql));
add_assoc_string_ex(single_error, "error", sizeof("error"), mysql_error(mysql->mysql));
add_next_index_zval(return_value, single_error);
zval single_error;
array_init(&single_error);
add_assoc_long_ex(&single_error, "errno", sizeof("errno") - 1, mysql_errno(mysql->mysql));
add_assoc_string_ex(&single_error, "sqlstate", sizeof("sqlstate") - 1, mysql_sqlstate(mysql->mysql));
add_assoc_string_ex(&single_error, "error", sizeof("error") - 1, mysql_error(mysql->mysql));
add_next_index_zval(return_value, &single_error);
}
#endif
}
/* }}} */
/* {{{ proto string mysqli_stmt_error_list(object stmt)
*/
PHP_FUNCTION(mysqli_stmt_error_list)
@ -470,7 +457,7 @@ PHP_FUNCTION(mysqli_stmt_error_list)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, &mysql_stmt, MYSQLI_STATUS_INITIALIZED);
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_INITIALIZED);
array_init(return_value);
#if defined(MYSQLI_USE_MYSQLND)
if (stmt->stmt && stmt->stmt->data && stmt->stmt->data->error_info->error_list) {
@ -480,30 +467,27 @@ PHP_FUNCTION(mysqli_stmt_error_list)
message;
message = (MYSQLND_ERROR_LIST_ELEMENT *) zend_llist_get_next_ex(stmt->stmt->data->error_info->error_list, &pos))
{
zval * single_error;
MAKE_STD_ZVAL(single_error);
array_init(single_error);
add_assoc_long_ex(single_error, "errno", sizeof("errno"), message->error_no);
add_assoc_string_ex(single_error, "sqlstate", sizeof("sqlstate"), message->sqlstate);
add_assoc_string_ex(single_error, "error", sizeof("error"), message->error);
add_next_index_zval(return_value, single_error);
zval single_error;
array_init(&single_error);
add_assoc_long_ex(&single_error, "errno", sizeof("errno") - 1, message->error_no);
add_assoc_string_ex(&single_error, "sqlstate", sizeof("sqlstate") - 1, message->sqlstate);
add_assoc_string_ex(&single_error, "error", sizeof("error") - 1, message->error);
add_next_index_zval(return_value, &single_error);
}
}
#else
if (mysql_stmt_errno(stmt->stmt)) {
zval * single_error;
MAKE_STD_ZVAL(single_error);
array_init(single_error);
add_assoc_long_ex(single_error, "errno", sizeof("errno"), mysql_stmt_errno(stmt->stmt));
add_assoc_string_ex(single_error, "sqlstate", sizeof("sqlstate"), mysql_stmt_sqlstate(stmt->stmt));
add_assoc_string_ex(single_error, "error", sizeof("error"), mysql_stmt_error(stmt->stmt));
add_next_index_zval(return_value, single_error);
zval single_error;
array_init(&single_error);
add_assoc_long_ex(&single_error, "errno", sizeof("errno") - 1, mysql_stmt_errno(stmt->stmt));
add_assoc_string_ex(&single_error, "sqlstate", sizeof("sqlstate") - 1, mysql_stmt_sqlstate(stmt->stmt));
add_assoc_string_ex(&single_error, "error", sizeof("error") - 1, mysql_stmt_error(stmt->stmt));
add_next_index_zval(return_value, &single_error);
}
#endif
}
/* }}} */
/* {{{ proto mixed mysqli_fetch_object (object result [, string class_name [, NULL|array ctor_params]])
Fetch a result row as an object */
PHP_FUNCTION(mysqli_fetch_object)
@ -524,7 +508,7 @@ PHP_FUNCTION(mysqli_multi_query)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, &query, &query_len) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
MYSQLI_ENABLE_MQ;
if (mysql_real_query(mysql->mysql, query, query_len)) {
@ -584,7 +568,7 @@ PHP_FUNCTION(mysqli_query)
RETURN_FALSE;
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
MYSQLI_DISABLE_MQ;
@ -647,7 +631,6 @@ PHP_FUNCTION(mysqli_query)
}
/* }}} */
#if defined(MYSQLI_USE_MYSQLND)
#include "php_network.h"
/* {{{ mysqlnd_zval_array_to_mysqlnd_array functions */
@ -687,7 +670,6 @@ static int mysqlnd_zval_array_to_mysqlnd_array(zval *in_array, MYSQLND ***out_ar
}
/* }}} */
/* {{{ mysqlnd_zval_array_from_mysqlnd_array */
static int mysqlnd_zval_array_from_mysqlnd_array(MYSQLND **in_array, zval *out_array TSRMLS_DC)
{
@ -738,48 +720,38 @@ static int mysqlnd_zval_array_from_mysqlnd_array(MYSQLND **in_array, zval *out_a
}
/* }}} */
/* {{{ mysqlnd_dont_poll_zval_array_from_mysqlnd_array */
static int mysqlnd_dont_poll_zval_array_from_mysqlnd_array(MYSQLND **in_array, zval *in_zval_array, zval *out_array TSRMLS_DC)
{
MYSQLND **p = in_array;
HashTable *new_hash;
zval **elem, **dest_elem;
zval proxy, *elem, *dest_elem;
int ret = 0;
ALLOC_HASHTABLE(new_hash);
zend_hash_init(new_hash, in_zval_array? zend_hash_num_elements(Z_ARRVAL_P(in_zval_array)):0, NULL, ZVAL_PTR_DTOR, 0);
array_init(&proxy);
if (in_array) {
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(in_zval_array));
zend_hash_get_current_data(Z_ARRVAL_P(in_zval_array), (void **) &elem) == SUCCESS;
zend_hash_move_forward(Z_ARRVAL_P(in_zval_array)))
{
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(in_zval_array), elem) {
MY_MYSQL *mysql;
mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*elem TSRMLS_CC);
mysql = (MY_MYSQL *) ((MYSQLI_RESOURCE *)intern->ptr)->ptr;
mysqli_object *intern = Z_MYSQLI_P(elem);
mysql = (MY_MYSQL *)((MYSQLI_RESOURCE *)intern->ptr)->ptr;
if (mysql->mysql == *p) {
zend_hash_next_index_insert(new_hash, (void *)elem, sizeof(zval *), (void **)&dest_elem);
dest_elem = zend_hash_next_index_insert(Z_ARRAY(proxy), elem);
if (dest_elem) {
zval_add_ref(dest_elem);
}
ret++;
p++;
}
}
} ZEND_HASH_FOREACH_END();
}
/* destroy old array and add new one */
zend_hash_destroy(Z_ARRVAL_P(out_array));
efree(Z_ARRVAL_P(out_array));
zend_hash_internal_pointer_reset(new_hash);
Z_ARRVAL_P(out_array) = new_hash;
zval_ptr_dtor(out_array);
ZVAL_COPY_VALUE(out_array, &proxy);
return 0;
}
/* }}} */
/* {{{ proto int mysqli_poll(array read, array write, array error, long sec [, long usec]) U
Poll connections */
PHP_FUNCTION(mysqli_poll)
@ -838,7 +810,6 @@ PHP_FUNCTION(mysqli_poll)
}
/* }}} */
/* {{{ proto int mysqli_reap_async_query(object link) U
Poll connections */
PHP_FUNCTION(mysqli_reap_async_query)
@ -852,7 +823,7 @@ PHP_FUNCTION(mysqli_reap_async_query)
return;
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
if (FAIL == mysqlnd_reap_async_query(mysql->mysql)) {
RETURN_FALSE;
@ -892,7 +863,6 @@ PHP_FUNCTION(mysqli_reap_async_query)
}
/* }}} */
/* {{{ proto object mysqli_stmt_get_result(object link) U
Buffer result set on client */
PHP_FUNCTION(mysqli_stmt_get_result)
@ -905,7 +875,7 @@ PHP_FUNCTION(mysqli_stmt_get_result)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, &mysql_stmt, MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
if (!(result = mysqlnd_stmt_get_result(stmt->stmt))) {
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
@ -920,7 +890,6 @@ PHP_FUNCTION(mysqli_stmt_get_result)
/* }}} */
#endif
/* {{{ proto object mysqli_get_warnings(object link) */
PHP_FUNCTION(mysqli_get_warnings)
{
@ -932,7 +901,7 @@ PHP_FUNCTION(mysqli_get_warnings)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
if (mysql_warning_count(mysql->mysql)) {
#ifdef MYSQLI_USE_MYSQLND
@ -950,7 +919,6 @@ PHP_FUNCTION(mysqli_get_warnings)
}
/* }}} */
/* {{{ proto object mysqli_stmt_get_warnings(object link) */
PHP_FUNCTION(mysqli_stmt_get_warnings)
{
@ -962,7 +930,7 @@ PHP_FUNCTION(mysqli_stmt_get_warnings)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &stmt_link, mysqli_stmt_class_entry) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, &stmt_link, MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE_STMT(stmt, stmt_link, MYSQLI_STATUS_VALID);
if (mysqli_stmt_warning_count(stmt->stmt)) {
w = php_get_warnings(mysqli_stmt_get_connection(stmt->stmt) TSRMLS_CC);
@ -976,7 +944,6 @@ PHP_FUNCTION(mysqli_stmt_get_warnings)
}
/* }}} */
#ifdef HAVE_MYSQLI_SET_CHARSET
/* {{{ proto bool mysqli_set_charset(object link, string csname)
sets client character set */
@ -990,7 +957,7 @@ PHP_FUNCTION(mysqli_set_charset)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, &cs_name, &csname_len) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
if (mysql_set_character_set(mysql->mysql, cs_name)) {
RETURN_FALSE;
@ -1018,7 +985,7 @@ PHP_FUNCTION(mysqli_get_charset)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
#if !defined(MYSQLI_USE_MYSQLND)
@ -1067,9 +1034,9 @@ static int mysqli_begin_transaction_libmysql(MYSQL * conn, const unsigned int mo
{
int ret;
zend_bool err = FALSE;
smart_str tmp_str = {0, 0, 0};
smart_str tmp_str = {0};
if (mode & TRANS_START_WITH_CONSISTENT_SNAPSHOT) {
if (tmp_str.len) {
if (tmp_str.s) {
smart_str_appendl(&tmp_str, ", ", sizeof(", ") - 1);
}
smart_str_appendl(&tmp_str, "WITH CONSISTENT SNAPSHOT", sizeof("WITH CONSISTENT SNAPSHOT") - 1);
@ -1079,12 +1046,12 @@ static int mysqli_begin_transaction_libmysql(MYSQL * conn, const unsigned int mo
php_error_docref(NULL TSRMLS_CC, E_WARNING, "This server version doesn't support 'READ WRITE' and 'READ ONLY'. Minimum 5.6.5 is required");
err = TRUE;
} else if (mode & TRANS_START_READ_WRITE) {
if (tmp_str.len) {
if (tmp_str.s) {
smart_str_appendl(&tmp_str, ", ", sizeof(", ") - 1);
}
smart_str_appendl(&tmp_str, "READ WRITE", sizeof("READ WRITE") - 1);
} else if (mode & TRANS_START_READ_ONLY) {
if (tmp_str.len) {
if (tmp_str.s) {
smart_str_appendl(&tmp_str, ", ", sizeof(", ") - 1);
}
smart_str_appendl(&tmp_str, "READ ONLY", sizeof("READ ONLY") - 1);
@ -1096,7 +1063,7 @@ static int mysqli_begin_transaction_libmysql(MYSQL * conn, const unsigned int mo
char * name_esc = mysqli_escape_string_for_tx_name_in_comment(name TSRMLS_CC);
char * query;
unsigned int query_len = spprintf(&query, 0, "START TRANSACTION%s %s",
name_esc? name_esc:"", tmp_str.c? tmp_str.c:"");
name_esc? name_esc:"", tmp_str.s? tmp_str.s->val:"");
smart_str_free(&tmp_str);
if (name_esc) {
@ -1125,7 +1092,7 @@ PHP_FUNCTION(mysqli_begin_transaction)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|ls", &mysql_link, mysqli_link_class_entry, &flags, &name, &name_len) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
if (flags < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid value for parameter flags (%ld)", flags);
err = TRUE;
@ -1151,7 +1118,6 @@ PHP_FUNCTION(mysqli_begin_transaction)
}
/* }}} */
#if !defined(MYSQLI_USE_MYSQLND)
/* {{{ proto bool mysqli_savepoint_libmysql */
static int mysqli_savepoint_libmysql(MYSQL * conn, const char * const name, zend_bool release)
@ -1166,7 +1132,6 @@ static int mysqli_savepoint_libmysql(MYSQL * conn, const char * const name, zend
/* }}} */
#endif
/* {{{ proto bool mysqli_savepoint(object link, string name)
Starts a transaction */
PHP_FUNCTION(mysqli_savepoint)
@ -1179,7 +1144,7 @@ PHP_FUNCTION(mysqli_savepoint)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, &name, &name_len) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
if (!name || !name_len) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Savepoint name cannot be empty");
RETURN_FALSE;
@ -1196,7 +1161,6 @@ PHP_FUNCTION(mysqli_savepoint)
}
/* }}} */
/* {{{ proto bool mysqli_release_savepoint(object link, string name)
Starts a transaction */
PHP_FUNCTION(mysqli_release_savepoint)
@ -1209,7 +1173,7 @@ PHP_FUNCTION(mysqli_release_savepoint)
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &mysql_link, mysqli_link_class_entry, &name, &name_len) == FAILURE) {
return;
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
if (!name || !name_len) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Savepoint name cannot be empty");
RETURN_FALSE;
@ -1225,7 +1189,6 @@ PHP_FUNCTION(mysqli_release_savepoint)
}
/* }}} */
/* {{{ proto bool mysqli_get_links_stats()
Returns information about open and cached links */
PHP_FUNCTION(mysqli_get_links_stats)
@ -1242,7 +1205,6 @@ PHP_FUNCTION(mysqli_get_links_stats)
/* }}} */
/*
* Local variables:
* tab-width: 4

View File

@ -84,8 +84,7 @@ extern PHPAPI zend_class_entry *spl_ce_RuntimeException;
#define PHP_MYSQLI_EXPORT(__type) PHP_MYSQLI_API __type
PHP_MYSQLI_EXPORT(zend_object_value) mysqli_objects_new(zend_class_entry * TSRMLS_DC);
PHP_MYSQLI_EXPORT(zend_object *) mysqli_objects_new(zend_class_entry * TSRMLS_DC);
#define MYSQLI_DISABLE_MQ if (mysql->multi_query) { \
mysql_set_server_option(mysql->mysql, MYSQL_OPTION_MULTI_STATEMENTS_OFF); \
@ -97,17 +96,14 @@ PHP_MYSQLI_EXPORT(zend_object_value) mysqli_objects_new(zend_class_entry * TSRML
mysql->multi_query = 1; \
}
#define MYSQLI_RETURN_LONG_LONG(__val) \
{ \
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); \
} \
RETURN_STR(strpprintf(0, MYSQLI_LLU_SPEC, (__val))); \
} \
}
#define MYSQLI_STORE_RESULT 0

View File

@ -34,16 +34,15 @@
#define CHECK_STATUS(value) \
if (!obj->ptr || ((MYSQLI_RESOURCE *)obj->ptr)->status < value ) { \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Property access is not allowed yet"); \
ZVAL_NULL(*retval); \
ZVAL_NULL(retval); \
return SUCCESS; \
} \
#define MYSQLI_GET_MYSQL(statusval) \
MYSQL *p; \
MAKE_STD_ZVAL(*retval);\
if (!obj->ptr || !(MY_MYSQL *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr) { \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", obj->zo.ce->name);\
ZVAL_NULL(*retval);\
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", obj->zo.ce->name->val);\
ZVAL_NULL(retval);\
return SUCCESS; \
} else { \
CHECK_STATUS(statusval);\
@ -52,10 +51,9 @@ if (!obj->ptr || !(MY_MYSQL *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr) { \
#define MYSQLI_GET_RESULT(statusval) \
MYSQL_RES *p; \
MAKE_STD_ZVAL(*retval);\
if (!obj->ptr) { \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", obj->zo.ce->name);\
ZVAL_NULL(*retval);\
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", obj->zo.ce->name->val);\
ZVAL_NULL(retval);\
return SUCCESS; \
} else { \
CHECK_STATUS(statusval);\
@ -65,10 +63,9 @@ if (!obj->ptr) { \
#define MYSQLI_GET_STMT(statusval) \
MYSQL_STMT *p; \
MAKE_STD_ZVAL(*retval);\
if (!obj->ptr) { \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", obj->zo.ce->name);\
ZVAL_NULL(*retval);\
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", obj->zo.ce->name->val);\
ZVAL_NULL(retval);\
return SUCCESS; \
} else { \
CHECK_STATUS(statusval);\
@ -76,133 +73,120 @@ if (!obj->ptr) { \
}
#define MYSQLI_MAP_PROPERTY_FUNC_LONG( __func, __int_func, __get_type, __ret_type, __ret_type_sprint_mod)\
static int __func(mysqli_object *obj, zval **retval TSRMLS_DC) \
static zval *__func(mysqli_object *obj, zval *retval TSRMLS_DC) \
{\
__ret_type l;\
__get_type;\
if (!p) {\
ZVAL_NULL(*retval);\
ZVAL_NULL(retval);\
} else {\
l = (__ret_type)__int_func(p);\
if (l < LONG_MAX) {\
ZVAL_LONG(*retval, (long) l);\
ZVAL_LONG(retval, (long) l);\
} else { \
char *ret; \
int ret_len = spprintf(&ret, 0, __ret_type_sprint_mod, l); \
ZVAL_STRINGL(*retval, ret, ret_len, 0); \
ZVAL_STR(retval, strpprintf(0, __ret_type_sprint_mod, l)); \
} \
}\
return SUCCESS;\
return retval;\
}
#define MYSQLI_MAP_PROPERTY_FUNC_STRING(__func, __int_func, __get_type)\
static int __func(mysqli_object *obj, zval **retval TSRMLS_DC)\
static zval *__func(mysqli_object *obj, zval *retval TSRMLS_DC)\
{\
char *c;\
__get_type;\
if (!p) {\
ZVAL_NULL(*retval);\
ZVAL_NULL(retval);\
} else {\
c = (char *)__int_func(p);\
if (!c) {\
ZVAL_NULL(*retval);\
ZVAL_NULL(retval);\
} else {\
ZVAL_STRING(*retval, c, 1);\
ZVAL_STRING(retval, c);\
}\
}\
return SUCCESS;\
return retval; \
}
/* {{{ property link_client_version_read */
static int link_client_version_read(mysqli_object *obj, zval **retval TSRMLS_DC)
static zval *link_client_version_read(mysqli_object *obj, zval *retval TSRMLS_DC)
{
MAKE_STD_ZVAL(*retval);
ZVAL_LONG(*retval, MYSQL_VERSION_ID);
return SUCCESS;
ZVAL_LONG(retval, MYSQL_VERSION_ID);
return retval;
}
/* }}} */
/* {{{ property link_client_info_read */
static int link_client_info_read(mysqli_object *obj, zval **retval TSRMLS_DC)
static zval *link_client_info_read(mysqli_object *obj, zval *retval TSRMLS_DC)
{
MAKE_STD_ZVAL(*retval);
CHECK_STATUS(MYSQLI_STATUS_INITIALIZED);
ZVAL_STRING(*retval, MYSQL_SERVER_VERSION, 1);
return SUCCESS;
ZVAL_STRING(retval, MYSQL_SERVER_VERSION);
return retval;
}
/* }}} */
/* {{{ property link_connect_errno_read */
static int link_connect_errno_read(mysqli_object *obj, zval **retval TSRMLS_DC)
static zval *link_connect_errno_read(mysqli_object *obj, zval *retval TSRMLS_DC)
{
MAKE_STD_ZVAL(*retval);
ZVAL_LONG(*retval, (long)MyG(error_no));
return SUCCESS;
ZVAL_LONG(retval, (long)MyG(error_no));
return retval;
}
/* }}} */
/* {{{ property link_connect_error_read */
static int link_connect_error_read(mysqli_object *obj, zval **retval TSRMLS_DC)
static zval *link_connect_error_read(mysqli_object *obj, zval *retval TSRMLS_DC)
{
MAKE_STD_ZVAL(*retval);
if (MyG(error_msg)) {
ZVAL_STRING(*retval, MyG(error_msg), 1);
ZVAL_STRING(retval, MyG(error_msg));
} else {
ZVAL_NULL(*retval);
ZVAL_NULL(retval);
}
return SUCCESS;
return retval;
}
/* }}} */
/* {{{ property link_affected_rows_read */
static int link_affected_rows_read(mysqli_object *obj, zval **retval TSRMLS_DC)
static zval *link_affected_rows_read(mysqli_object *obj, zval *retval TSRMLS_DC)
{
MY_MYSQL *mysql;
my_ulonglong rc;
MAKE_STD_ZVAL(*retval);
CHECK_STATUS(MYSQLI_STATUS_INITIALIZED);
mysql = (MY_MYSQL *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;
if (!mysql) {
ZVAL_NULL(*retval);
ZVAL_NULL(retval);
} else {
CHECK_STATUS(MYSQLI_STATUS_VALID);
rc = mysql_affected_rows(mysql->mysql);
if (rc == (my_ulonglong) -1) {
ZVAL_LONG(*retval, -1);
return SUCCESS;
ZVAL_LONG(retval, -1);
return retval;
}
if (rc < LONG_MAX) {
ZVAL_LONG(*retval, (long) rc);
ZVAL_LONG(retval, (long) rc);
} else {
char *ret;
int l = spprintf(&ret, 0, MYSQLI_LLU_SPEC, rc);
ZVAL_STRINGL(*retval, ret, l, 0);
ZVAL_STR(retval, strpprintf(0, MYSQLI_LLU_SPEC, rc));
}
}
return SUCCESS;
return retval;
}
/* }}} */
/* {{{ property link_error_list_read */
static int link_error_list_read(mysqli_object *obj, zval **retval TSRMLS_DC)
static zval *link_error_list_read(mysqli_object *obj, zval *retval TSRMLS_DC)
{
MY_MYSQL *mysql;
MAKE_STD_ZVAL(*retval);
CHECK_STATUS(MYSQLI_STATUS_VALID);
mysql = (MY_MYSQL *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;
array_init(*retval);
array_init(retval);
if (mysql) {
#if defined(MYSQLI_USE_MYSQLND)
if (mysql->mysql->data->error_info->error_list) {
@ -212,32 +196,30 @@ static int link_error_list_read(mysqli_object *obj, zval **retval TSRMLS_DC)
message;
message = (MYSQLND_ERROR_LIST_ELEMENT *) zend_llist_get_next_ex(mysql->mysql->data->error_info->error_list, &pos))
{
zval * single_error;
MAKE_STD_ZVAL(single_error);
array_init(single_error);
add_assoc_long_ex(single_error, "errno", sizeof("errno"), message->error_no);
add_assoc_string_ex(single_error, "sqlstate", sizeof("sqlstate"), message->sqlstate);
add_assoc_string_ex(single_error, "error", sizeof("error"), message->error);
add_next_index_zval(*retval, single_error);
zval single_error;
array_init(&single_error);
add_assoc_long_ex(&single_error, "errno", sizeof("errno") - 1, message->error_no);
add_assoc_string_ex(&single_error, "sqlstate", sizeof("sqlstate") - 1, message->sqlstate);
add_assoc_string_ex(&single_error, "error", sizeof("error") - 1, message->error);
add_next_index_zval(retval, &single_error);
}
}
#else
if (mysql_errno(mysql->mysql)) {
zval * single_error;
MAKE_STD_ZVAL(single_error);
array_init(single_error);
add_assoc_long_ex(single_error, "errno", sizeof("errno"), mysql_errno(mysql->mysql));
add_assoc_string_ex(single_error, "sqlstate", sizeof("sqlstate"), mysql_sqlstate(mysql->mysql));
add_assoc_string_ex(single_error, "error", sizeof("error"), mysql_error(mysql->mysql));
add_next_index_zval(*retval, single_error);
zval single_error;
array_init(&single_error);
add_assoc_long_ex(&single_error, "errno", sizeof("errno") - 1, mysql_errno(mysql->mysql));
add_assoc_string_ex(&single_error, "sqlstate", sizeof("sqlstate") - 1, mysql_sqlstate(mysql->mysql));
add_assoc_string_ex(&single_error, "error", sizeof("error") - 1, mysql_error(mysql->mysql));
add_next_index_zval(retval, &single_error);
}
#endif
}
return SUCCESS;
return retval;
}
/* }}} */
/* link properties */
MYSQLI_MAP_PROPERTY_FUNC_LONG(link_errno_read, mysql_errno, MYSQLI_GET_MYSQL(MYSQLI_STATUS_INITIALIZED), ulong, "%lu")
MYSQLI_MAP_PROPERTY_FUNC_STRING(link_error_read, mysql_error, MYSQLI_GET_MYSQL(MYSQLI_STATUS_INITIALIZED))
@ -253,12 +235,11 @@ MYSQLI_MAP_PROPERTY_FUNC_LONG(link_thread_id_read, mysql_thread_id, MYSQLI_GET_M
MYSQLI_MAP_PROPERTY_FUNC_LONG(link_warning_count_read, mysql_warning_count, MYSQLI_GET_MYSQL(MYSQLI_STATUS_VALID), ulong, "%lu")
/* {{{ property link_stat_read */
static int link_stat_read(mysqli_object *obj, zval **retval TSRMLS_DC)
static zval *link_stat_read(mysqli_object *obj, zval *retval TSRMLS_DC)
{
MY_MYSQL *mysql;
MAKE_STD_ZVAL(*retval);
ZVAL_NULL(*retval);
ZVAL_NULL(retval);
#if defined(MYSQLI_USE_MYSQLND)
CHECK_STATUS(MYSQLI_STATUS_INITIALIZED);
@ -273,67 +254,63 @@ static int link_stat_read(mysqli_object *obj, zval **retval TSRMLS_DC)
#if defined(MYSQLI_USE_MYSQLND)
uint stat_msg_len;
if (mysqlnd_stat(mysql->mysql, &stat_msg, &stat_msg_len) == PASS) {
ZVAL_STRINGL(*retval, stat_msg, stat_msg_len, 0);
ZVAL_STRINGL(retval, stat_msg, stat_msg_len);
efree(stat_msg);
}
#else
if ((stat_msg = (char *) mysql_stat(mysql->mysql))) {
ZVAL_STRING(*retval, stat_msg, 1);
if ((stat_msg = (char *)mysql_stat(mysql->mysql))) {
ZVAL_STRING(retval, stat_msg);
}
#endif
}
return SUCCESS;
return retval;
}
/* }}} */
/* result properties */
/* {{{ property result_type_read */
static int result_type_read(mysqli_object *obj, zval **retval TSRMLS_DC)
static zval *result_type_read(mysqli_object *obj, zval *retval TSRMLS_DC)
{
MYSQL_RES *p;
MAKE_STD_ZVAL(*retval);
CHECK_STATUS(MYSQLI_STATUS_VALID);
p = (MYSQL_RES *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;
if (!p) {
ZVAL_NULL(*retval);
ZVAL_NULL(retval);
} else {
ZVAL_LONG(*retval, mysqli_result_is_unbuffered(p) ? MYSQLI_USE_RESULT:MYSQLI_STORE_RESULT);
ZVAL_LONG(retval, mysqli_result_is_unbuffered(p) ? MYSQLI_USE_RESULT:MYSQLI_STORE_RESULT);
}
return SUCCESS;
return retval;
}
/* }}} */
/* {{{ property result_lengths_read */
static int result_lengths_read(mysqli_object *obj, zval **retval TSRMLS_DC)
static zval *result_lengths_read(mysqli_object *obj, zval *retval TSRMLS_DC)
{
MYSQL_RES *p;
ulong *ret;
uint field_count;
MAKE_STD_ZVAL(*retval);
CHECK_STATUS(MYSQLI_STATUS_VALID);
p = (MYSQL_RES *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;
field_count = mysql_num_fields(p);
if (!p || !field_count || !(ret = mysql_fetch_lengths(p))) {
ZVAL_NULL(*retval);
ZVAL_NULL(retval);
} else {
ulong i;
array_init(*retval);
array_init(retval);
for (i = 0; i < field_count; i++) {
add_index_long(*retval, i, ret[i]);
add_index_long(retval, i, ret[i]);
}
}
return SUCCESS;
return retval;
}
/* }}} */
MYSQLI_MAP_PROPERTY_FUNC_LONG(result_current_field_read, mysql_field_tell, MYSQLI_GET_RESULT(MYSQLI_STATUS_VALID), ulong, "%lu")
MYSQLI_MAP_PROPERTY_FUNC_LONG(result_field_count_read, mysql_num_fields, MYSQLI_GET_RESULT(MYSQLI_STATUS_VALID), ulong, "%lu")
MYSQLI_MAP_PROPERTY_FUNC_LONG(result_num_rows_read, mysql_num_rows, MYSQLI_GET_RESULT(MYSQLI_STATUS_VALID), my_ulonglong, MYSQLI_LLU_SPEC)
@ -341,67 +318,62 @@ MYSQLI_MAP_PROPERTY_FUNC_LONG(result_num_rows_read, mysql_num_rows, MYSQLI_GET_R
/* statement properties */
/* {{{ property stmt_id_read */
static int stmt_id_read(mysqli_object *obj, zval **retval TSRMLS_DC)
static zval *stmt_id_read(mysqli_object *obj, zval *retval TSRMLS_DC)
{
MY_STMT *p;
MAKE_STD_ZVAL(*retval);
CHECK_STATUS(MYSQLI_STATUS_VALID);
p = (MY_STMT*)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;
if (!p) {
ZVAL_NULL(*retval);
ZVAL_NULL(retval);
} else {
ZVAL_LONG(*retval, mysqli_stmt_get_id(p->stmt));
ZVAL_LONG(retval, mysqli_stmt_get_id(p->stmt));
}
return SUCCESS;
return retval;
}
/* }}} */
/* {{{ property stmt_affected_rows_read */
static int stmt_affected_rows_read(mysqli_object *obj, zval **retval TSRMLS_DC)
static zval *stmt_affected_rows_read(mysqli_object *obj, zval *retval TSRMLS_DC)
{
MY_STMT *p;
my_ulonglong rc;
MAKE_STD_ZVAL(*retval);
CHECK_STATUS(MYSQLI_STATUS_VALID);
p = (MY_STMT *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;
if (!p) {
ZVAL_NULL(*retval);
ZVAL_NULL(retval);
} else {
rc = mysql_stmt_affected_rows(p->stmt);
if (rc == (my_ulonglong) -1) {
ZVAL_LONG(*retval, -1);
return SUCCESS;
ZVAL_LONG(retval, -1);
return retval;
}
if (rc < LONG_MAX) {
ZVAL_LONG(*retval, (long) rc);
ZVAL_LONG(retval, (long) rc);
} else {
char *ret;
int l = spprintf(&ret, 0, MYSQLI_LLU_SPEC, rc);
ZVAL_STRINGL(*retval, ret, l, 0);
ZVAL_STR(retval, strpprintf(0, MYSQLI_LLU_SPEC, rc));
}
}
return SUCCESS;
return retval;
}
/* }}} */
/* {{{ property stmt_error_list_read */
static int stmt_error_list_read(mysqli_object *obj, zval **retval TSRMLS_DC)
static zval *stmt_error_list_read(mysqli_object *obj, zval *retval TSRMLS_DC)
{
MY_STMT * stmt;
MAKE_STD_ZVAL(*retval);
CHECK_STATUS(MYSQLI_STATUS_INITIALIZED);
stmt = (MY_STMT *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;
array_init(*retval);
array_init(retval);
if (stmt && stmt->stmt) {
#if defined(MYSQLI_USE_MYSQLND)
if (stmt->stmt->data && stmt->stmt->data->error_info->error_list) {
@ -411,32 +383,29 @@ static int stmt_error_list_read(mysqli_object *obj, zval **retval TSRMLS_DC)
message;
message = (MYSQLND_ERROR_LIST_ELEMENT *) zend_llist_get_next_ex(stmt->stmt->data->error_info->error_list, &pos))
{
zval * single_error;
MAKE_STD_ZVAL(single_error);
array_init(single_error);
add_assoc_long_ex(single_error, "errno", sizeof("errno"), message->error_no);
add_assoc_string_ex(single_error, "sqlstate", sizeof("sqlstate"), message->sqlstate);
add_assoc_string_ex(single_error, "error", sizeof("error"), message->error);
add_next_index_zval(*retval, single_error);
zval single_error;
array_init(&single_error);
add_assoc_long_ex(&single_error, "errno", sizeof("errno") - 1, message->error_no);
add_assoc_string_ex(&single_error, "sqlstate", sizeof("sqlstate") - 1, message->sqlstate);
add_assoc_string_ex(&single_error, "error", sizeof("error") - 1, message->error);
add_next_index_zval(retval, &single_error);
}
}
#else
if (mysql_stmt_errno(stmt->stmt)) {
zval * single_error;
MAKE_STD_ZVAL(single_error);
array_init(single_error);
add_assoc_long_ex(single_error, "errno", sizeof("errno"), mysql_stmt_errno(stmt->stmt));
add_assoc_string_ex(single_error, "sqlstate", sizeof("sqlstate"), mysql_stmt_sqlstate(stmt->stmt));
add_assoc_string_ex(single_error, "error", sizeof("error"), mysql_stmt_error(stmt->stmt));
add_next_index_zval(*retval, single_error);
zval single_error;
array_init(&single_error);
add_assoc_long_ex(&single_error, "errno", sizeof("errno") - 1, mysql_stmt_errno(stmt->stmt));
add_assoc_string_ex(&single_error, "sqlstate", sizeof("sqlstate") - 1, mysql_stmt_sqlstate(stmt->stmt));
add_assoc_string_ex(&single_error, "error", sizeof("error") - 1, mysql_stmt_error(stmt->stmt));
add_next_index_zval(retval, &single_error);
}
#endif
}
return SUCCESS;
return retval;
}
/* }}} */
MYSQLI_MAP_PROPERTY_FUNC_LONG(stmt_insert_id_read, mysql_stmt_insert_id, MYSQLI_GET_STMT(MYSQLI_STATUS_VALID), my_ulonglong, MYSQLI_LLU_SPEC)
MYSQLI_MAP_PROPERTY_FUNC_LONG(stmt_num_rows_read, mysql_stmt_num_rows, MYSQLI_GET_STMT(MYSQLI_STATUS_VALID), my_ulonglong, MYSQLI_LLU_SPEC)
MYSQLI_MAP_PROPERTY_FUNC_LONG(stmt_param_count_read, mysql_stmt_param_count, MYSQLI_GET_STMT(MYSQLI_STATUS_VALID), ulong, "%lu")
@ -470,30 +439,6 @@ const mysqli_property_entry mysqli_link_property_entries[] = {
};
const zend_property_info mysqli_link_property_info_entries[] = {
{ZEND_ACC_PUBLIC, "affected_rows", sizeof("affected_rows") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "client_info", sizeof("client_info") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "client_version", sizeof("client_version") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "connect_errno", sizeof("connect_errno") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "connect_error", sizeof("connect_error") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "errno", sizeof("errno") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "error", sizeof("error") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "error_list", sizeof("error_list") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "field_count", sizeof("field_count") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "host_info", sizeof("host_info") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "info", sizeof("info") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "insert_id", sizeof("insert_id") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "server_info", sizeof("server_info") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "server_version", sizeof("server_version") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "stat", sizeof("stat") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "sqlstate", sizeof("sqlstate") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "protocol_version", sizeof("protocol_version")-1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "thread_id", sizeof("thread_id") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "warning_count", sizeof("warning_count") - 1, -1, 0, NULL, 0, NULL},
{0, NULL, 0, -1, 0, NULL, 0, NULL}
};
const mysqli_property_entry mysqli_result_property_entries[] = {
{"current_field",sizeof("current_field")-1, result_current_field_read, NULL},
{"field_count", sizeof("field_count") - 1, result_field_count_read, NULL},
@ -503,15 +448,6 @@ const mysqli_property_entry mysqli_result_property_entries[] = {
{NULL, 0, NULL, NULL}
};
const zend_property_info mysqli_result_property_info_entries[] = {
{ZEND_ACC_PUBLIC, "current_field", sizeof("current_field")-1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "field_count", sizeof("field_count") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "lengths", sizeof("lengths") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "num_rows", sizeof("num_rows") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "type", sizeof("type") - 1, -1, 0, NULL, 0, NULL},
{0, NULL, 0, -1, 0, NULL, 0, NULL}
};
const mysqli_property_entry mysqli_stmt_property_entries[] = {
{"affected_rows", sizeof("affected_rows")-1,stmt_affected_rows_read, NULL},
{"insert_id", sizeof("insert_id") - 1, stmt_insert_id_read, NULL},
@ -526,21 +462,6 @@ const mysqli_property_entry mysqli_stmt_property_entries[] = {
{NULL, 0, NULL, NULL}
};
const zend_property_info mysqli_stmt_property_info_entries[] = {
{ZEND_ACC_PUBLIC, "affected_rows", sizeof("affected_rows") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "insert_id", sizeof("insert_id") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "num_rows", sizeof("num_rows") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "param_count",sizeof("param_count") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "field_count",sizeof("field_count") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "errno", sizeof("errno") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "error", sizeof("error") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "error_list", sizeof("error_list") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "sqlstate", sizeof("sqlstate") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "id", sizeof("id") - 1, -1, 0, NULL, 0, NULL},
{0, NULL, 0, -1, 0, NULL, 0, NULL}
};
/*
* Local variables:
* tab-width: 4

View File

@ -38,7 +38,7 @@ extern zend_object_iterator_funcs php_mysqli_result_iterator_funcs;
typedef struct {
zend_object_iterator intern;
mysqli_object *result;
zval *current_row;
zval current_row;
my_longlong row_num;
} php_mysqli_result_iterator;
@ -52,55 +52,46 @@ zend_object_iterator *php_mysqli_result_get_iterator(zend_class_entry *ce, zval
zend_error(E_ERROR, "An iterator cannot be used with foreach by reference");
}
iterator = ecalloc(1, sizeof(php_mysqli_result_iterator));
zend_iterator_init(&iterator->intern TSRMLS_CC);
Z_ADDREF_P(object);
iterator->intern.data = (void*)object;
ZVAL_COPY(&iterator->intern.data, object);
iterator->intern.funcs = &php_mysqli_result_iterator_funcs;
iterator->result = (mysqli_object *) zend_object_store_get_object(object TSRMLS_CC);
iterator->result = Z_MYSQLI_P(object);
iterator->row_num = -1;
return (zend_object_iterator*)iterator;
return &iterator->intern;
}
/* }}} */
/* {{{ */
static void php_mysqli_result_iterator_dtor(zend_object_iterator *iter TSRMLS_DC)
{
php_mysqli_result_iterator *iterator = (php_mysqli_result_iterator*) iter;
php_mysqli_result_iterator *iterator = (php_mysqli_result_iterator*)iter;
/* cleanup handled in sxe_object_dtor as we dont always have an iterator wrapper */
if (iterator->intern.data) {
zval_ptr_dtor((zval**)&iterator->intern.data);
}
if (iterator->current_row) {
zval_ptr_dtor(&iterator->current_row);
}
efree(iterator);
zval_ptr_dtor(&iterator->intern.data);
zval_ptr_dtor(&iterator->current_row);
}
/* }}} */
/* {{{ */
static int php_mysqli_result_iterator_valid(zend_object_iterator *iter TSRMLS_DC)
{
php_mysqli_result_iterator *iterator = (php_mysqli_result_iterator*) iter;
return iterator->current_row && Z_TYPE_P(iterator->current_row) == IS_ARRAY ? SUCCESS : FAILURE;
return Z_TYPE(iterator->current_row) == IS_ARRAY ? SUCCESS : FAILURE;
}
/* }}} */
/* {{{ */
static void php_mysqli_result_iterator_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC)
static zval *php_mysqli_result_iterator_current_data(zend_object_iterator *iter TSRMLS_DC)
{
php_mysqli_result_iterator *iterator = (php_mysqli_result_iterator*) iter;
*data = &iterator->current_row;
return &iterator->current_row;
}
/* }}} */
/* {{{ */
static void php_mysqli_result_iterator_move_forward(zend_object_iterator *iter TSRMLS_DC)
{
@ -110,18 +101,15 @@ static void php_mysqli_result_iterator_move_forward(zend_object_iterator *iter T
MYSQL_RES *result;
MYSQLI_FETCH_RESOURCE_BY_OBJ(result, MYSQL_RES *, intern, "mysqli_result", MYSQLI_STATUS_VALID);
if (iterator->current_row) {
zval_ptr_dtor(&iterator->current_row);
}
MAKE_STD_ZVAL(iterator->current_row);
php_mysqli_fetch_into_hash_aux(iterator->current_row, result, MYSQLI_ASSOC TSRMLS_CC);
if (Z_TYPE_P(iterator->current_row) == IS_ARRAY) {
zval_ptr_dtor(&iterator->current_row);
php_mysqli_fetch_into_hash_aux(&iterator->current_row, result, MYSQLI_ASSOC TSRMLS_CC);
if (Z_TYPE(iterator->current_row) == IS_ARRAY) {
iterator->row_num++;
}
}
/* }}} */
/* {{{ */
static void php_mysqli_result_iterator_rewind(zend_object_iterator *iter TSRMLS_DC)
{
@ -148,7 +136,6 @@ static void php_mysqli_result_iterator_rewind(zend_object_iterator *iter TSRMLS_
}
/* }}} */
/* {{{ php_mysqli_result_iterator_current_key */
static void php_mysqli_result_iterator_current_key(zend_object_iterator *iter, zval *key TSRMLS_DC)
{
@ -158,7 +145,6 @@ static void php_mysqli_result_iterator_current_key(zend_object_iterator *iter, z
}
/* }}} */
/* {{{ php_mysqli_result_iterator_funcs */
zend_object_iterator_funcs php_mysqli_result_iterator_funcs = {
php_mysqli_result_iterator_dtor,
@ -170,7 +156,6 @@ zend_object_iterator_funcs php_mysqli_result_iterator_funcs = {
};
/* }}} */
/*
* Local variables:
* tab-width: 4

View File

@ -32,9 +32,8 @@
#define ZSTR_DUPLICATE (1<<0)
#define ZSTR_AUTOFREE (1<<1)
#define ZVAL_UTF8_STRING(z, s, flags) ZVAL_STRING((z), (char*)(s), ((flags) & ZSTR_DUPLICATE))
#define ZVAL_UTF8_STRINGL(z, s, l, flags) ZVAL_STRINGL((z), (char*)(s), (l), ((flags) & ZSTR_DUPLICATE))
#define ZVAL_UTF8_STRING(z, s, flags) ZVAL_STRING((z), (char*)(s))
#define ZVAL_UTF8_STRINGL(z, s, l, flags) ZVAL_STRINGL((z), (char*)(s), (l))
/* {{{ void php_clear_warnings() */
void php_clear_warnings(MYSQLI_WARNING *w)
@ -51,7 +50,6 @@ void php_clear_warnings(MYSQLI_WARNING *w)
}
/* }}} */
#ifndef MYSQLI_USE_MYSQLND
/* {{{ MYSQLI_WARNING *php_new_warning */
static
@ -71,7 +69,6 @@ MYSQLI_WARNING *php_new_warning(const char *reason, int errorno TSRMLS_DC)
}
/* }}} */
/* {{{ MYSQLI_WARNING *php_get_warnings(MYSQL *mysql TSRMLS_DC) */
MYSQLI_WARNING *php_get_warnings(MYSQL *mysql TSRMLS_DC)
{
@ -108,10 +105,10 @@ MYSQLI_WARNING *php_new_warning(const zval * reason, int errorno TSRMLS_DC)
w = (MYSQLI_WARNING *)ecalloc(1, sizeof(MYSQLI_WARNING));
w->reason = *reason;
zval_copy_ctor(&(w->reason));
ZVAL_DUP(&w->reason, reason);
convert_to_string(&w->resson);
ZVAL_UTF8_STRINGL(&(w->reason), Z_STRVAL(w->reason), Z_STRLEN(w->reason), ZSTR_AUTOFREE);
//????ZVAL_UTF8_STRINGL(&(w->reason), Z_STRVAL(w->reason), Z_STRLEN(w->reason), ZSTR_AUTOFREE);
ZVAL_UTF8_STRINGL(&(w->sqlstate), "HY000", sizeof("HY000") - 1, ZSTR_DUPLICATE);
@ -121,7 +118,6 @@ MYSQLI_WARNING *php_new_warning(const zval * reason, int errorno TSRMLS_DC)
}
/* }}} */
/* {{{ MYSQLI_WARNING *php_get_warnings(MYSQL *mysql TSRMLS_DC) */
MYSQLI_WARNING * php_get_warnings(MYSQLND_CONN_DATA * mysql TSRMLS_DC)
{
@ -181,13 +177,12 @@ MYSQLI_WARNING * php_get_warnings(MYSQLND_CONN_DATA * mysql TSRMLS_DC)
/* }}} */
#endif
/* {{{ bool mysqli_warning::next() */
PHP_METHOD(mysqli_warning, next)
{
MYSQLI_WARNING *w;
zval *mysqli_warning;
mysqli_object *obj = (mysqli_object *)zend_objects_get_address(getThis() TSRMLS_CC);
mysqli_object *obj = Z_MYSQLI_P(getThis());
if (obj->ptr) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
@ -195,7 +190,7 @@ PHP_METHOD(mysqli_warning, next)
return;
}
MYSQLI_FETCH_RESOURCE(w, MYSQLI_WARNING *, &mysqli_warning, "mysqli_warning", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(w, MYSQLI_WARNING *, mysqli_warning, "mysqli_warning", MYSQLI_STATUS_VALID);
if (w && w->next) {
w = w->next;
@ -207,57 +202,49 @@ PHP_METHOD(mysqli_warning, next)
}
/* }}} */
/* {{{ property mysqli_warning_message */
static
int mysqli_warning_message(mysqli_object *obj, zval **retval TSRMLS_DC)
zval *mysqli_warning_message(mysqli_object *obj, zval *retval TSRMLS_DC)
{
MYSQLI_WARNING *w;
if (!obj->ptr || !((MYSQLI_RESOURCE *)(obj->ptr))->ptr) {
return FAILURE;
return NULL;
}
w = (MYSQLI_WARNING *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;
MAKE_STD_ZVAL(*retval);
**retval = w->reason;
zval_copy_ctor(*retval);
return SUCCESS;
ZVAL_COPY(retval, &w->reason);
return retval;
}
/* }}} */
/* {{{ property mysqli_warning_sqlstate */
static
int mysqli_warning_sqlstate(mysqli_object *obj, zval **retval TSRMLS_DC)
zval *mysqli_warning_sqlstate(mysqli_object *obj, zval *retval TSRMLS_DC)
{
MYSQLI_WARNING *w;
if (!obj->ptr || !((MYSQLI_RESOURCE *)(obj->ptr))->ptr) {
return FAILURE;
return NULL;
}
w = (MYSQLI_WARNING *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;
MAKE_STD_ZVAL(*retval);
**retval = w->sqlstate;
zval_copy_ctor(*retval);
return SUCCESS;
ZVAL_COPY(retval, &w->sqlstate);
return retval;
}
/* }}} */
/* {{{ property mysqli_warning_error */
static
int mysqli_warning_errno(mysqli_object *obj, zval **retval TSRMLS_DC)
zval *mysqli_warning_errno(mysqli_object *obj, zval *retval TSRMLS_DC)
{
MYSQLI_WARNING *w;
if (!obj->ptr || !((MYSQLI_RESOURCE *)(obj->ptr))->ptr) {
return FAILURE;
return NULL;
}
w = (MYSQLI_WARNING *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;
MAKE_STD_ZVAL(*retval);
ZVAL_LONG(*retval, w->errorno);
ZVAL_LONG(retval, w->errorno);
return SUCCESS;
}
/* }}} */
@ -279,11 +266,11 @@ PHP_METHOD(mysqli_warning, __construct)
if (zend_parse_parameters(1 TSRMLS_CC, "o", &z)==FAILURE) {
return;
}
obj = (mysqli_object *)zend_object_store_get_object(z TSRMLS_CC);\
obj = Z_MYSQLI_P(z);
if (obj->zo.ce == mysqli_link_class_entry) {
MY_MYSQL *mysql;
MYSQLI_FETCH_RESOURCE_CONN(mysql, &z, MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE_CONN(mysql, z, MYSQLI_STATUS_VALID);
if (mysql_warning_count(mysql->mysql)) {
#ifndef MYSQLI_USE_MYSQLND
w = php_get_warnings(mysql->mysql TSRMLS_CC);
@ -296,7 +283,7 @@ PHP_METHOD(mysqli_warning, __construct)
}
} else if (obj->zo.ce == mysqli_stmt_class_entry) {
MY_STMT *stmt;
MYSQLI_FETCH_RESOURCE_STMT(stmt, &z, MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE_STMT(stmt, z, MYSQLI_STATUS_VALID);
#ifndef MYSQLI_USE_MYSQLND
hdl = mysqli_stmt_get_connection(stmt->stmt);
if (mysql_warning_count(hdl)) {
@ -321,7 +308,7 @@ PHP_METHOD(mysqli_warning, __construct)
if (!getThis() || !instanceof_function(Z_OBJCE_P(getThis()), mysqli_warning_class_entry TSRMLS_CC)) {
MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_warning_class_entry);
} else {
((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->ptr = mysqli_resource;
(Z_MYSQLI_P(getThis()))->ptr = mysqli_resource;
}
}
@ -344,16 +331,6 @@ const mysqli_property_entry mysqli_warning_property_entries[] = {
};
/* }}} */
/* {{{ mysqli_warning_property_info_entries */
const zend_property_info mysqli_warning_property_info_entries[] = {
{ZEND_ACC_PUBLIC, "message", sizeof("message") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "sqlstate", sizeof("sqlstate") - 1, -1, 0, NULL, 0, NULL},
{ZEND_ACC_PUBLIC, "errno", sizeof("errno") - 1, -1, 0, NULL, 0, NULL},
{0, NULL, 0, -1, 0, NULL, 0, NULL}
};
/* }}} */
/*
* Local variables:
* tab-width: 4

View File

@ -107,7 +107,7 @@ typedef struct {
typedef struct {
unsigned int var_cnt;
VAR_BUFFER *buf;
zval **vars;
zval *vars;
char *is_null;
} BIND_BUFFER;
@ -118,14 +118,14 @@ typedef struct {
char *query;
#ifndef MYSQLI_USE_MYSQLND
/* used to manage refcount with libmysql (already implement in mysqlnd) */
zend_object_handle link_handle;
zval link_handle;
#endif
} MY_STMT;
typedef struct {
MYSQL *mysql;
char *hash_key;
zval *li_read;
zend_string *hash_key;
zval li_read;
php_stream *li_stream;
unsigned int multi_query;
zend_bool persistent;
@ -141,11 +141,17 @@ typedef struct {
} MYSQLI_RESOURCE;
typedef struct _mysqli_object {
zend_object zo;
void *ptr;
HashTable *prop_handler;
zend_object zo;
} mysqli_object; /* extends zend_object */
static inline mysqli_object *php_mysqli_fetch_object(zend_object *obj) {
return (mysqli_object *)((char*)(obj) - XtOffsetOf(mysqli_object, zo));
}
#define Z_MYSQLI_P(zv) php_mysqli_fetch_object(Z_OBJ_P((zv)))
typedef struct st_mysqli_warning MYSQLI_WARNING;
struct st_mysqli_warning {
@ -158,11 +164,10 @@ struct st_mysqli_warning {
typedef struct _mysqli_property_entry {
const char *pname;
size_t pname_length;
int (*r_func)(mysqli_object *obj, zval **retval TSRMLS_DC);
zval *(*r_func)(mysqli_object *obj, zval *retval TSRMLS_DC);
int (*w_func)(mysqli_object *obj, zval *value TSRMLS_DC);
} mysqli_property_entry;
typedef struct {
zend_ptr_stack free_links;
} mysqli_plist_entry;
@ -233,35 +238,33 @@ extern PHPAPI zend_class_entry *spl_ce_RuntimeException;
} \
#define MYSQLI_REGISTER_RESOURCE_EX(__ptr, __zval) \
((mysqli_object *) zend_object_store_get_object(__zval TSRMLS_CC))->ptr = __ptr;
(Z_MYSQLI_P(__zval))->ptr = __ptr;
#define MYSQLI_RETURN_RESOURCE(__ptr, __ce) \
Z_TYPE_P(return_value) = IS_OBJECT; \
(return_value)->value.obj = mysqli_objects_new(__ce TSRMLS_CC); \
RETVAL_OBJ(mysqli_objects_new(__ce TSRMLS_CC)); \
MYSQLI_REGISTER_RESOURCE_EX(__ptr, return_value)
#define MYSQLI_REGISTER_RESOURCE(__ptr, __ce) \
{\
zval *object = getThis();\
if (!object || !instanceof_function(Z_OBJCE_P(object), mysqli_link_class_entry TSRMLS_CC)) {\
object = return_value;\
Z_TYPE_P(object) = IS_OBJECT;\
(object)->value.obj = mysqli_objects_new(__ce TSRMLS_CC);\
}\
zval *object = getThis(); \
if (!object || !instanceof_function(Z_OBJCE_P(object), mysqli_link_class_entry TSRMLS_CC)) { \
object = return_value; \
ZVAL_OBJ(object, mysqli_objects_new(__ce TSRMLS_CC)); \
} \
MYSQLI_REGISTER_RESOURCE_EX(__ptr, object)\
}
#define MYSQLI_FETCH_RESOURCE(__ptr, __type, __id, __name, __check) \
{ \
MYSQLI_RESOURCE *my_res; \
mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\
mysqli_object *intern = Z_MYSQLI_P(__id); \
if (!(my_res = (MYSQLI_RESOURCE *)intern->ptr)) {\
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", intern->zo.ce->name);\
RETURN_NULL();\
}\
__ptr = (__type)my_res->ptr; \
if (__check && my_res->status < __check) { \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid object or resource %s\n", intern->zo.ce->name); \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid object or resource %s\n", intern->zo.ce->name->val); \
RETURN_NULL();\
}\
}
@ -270,24 +273,23 @@ extern PHPAPI zend_class_entry *spl_ce_RuntimeException;
{ \
MYSQLI_RESOURCE *my_res; \
if (!(my_res = (MYSQLI_RESOURCE *)(__obj->ptr))) {\
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", intern->zo.ce->name);\
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", intern->zo.ce->name->val);\
return;\
}\
__ptr = (__type)my_res->ptr; \
if (__check && my_res->status < __check) { \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid object or resource %s\n", intern->zo.ce->name); \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid object or resource %s\n", intern->zo.ce->name->val); \
return;\
}\
}
#define MYSQLI_FETCH_RESOURCE_CONN(__ptr, __id, __check) \
{ \
MYSQLI_FETCH_RESOURCE((__ptr), MY_MYSQL *, (__id), "mysqli_link", (__check)); \
if (!(__ptr)->mysql) { \
mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\
php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid object or resource %s\n", intern->zo.ce->name); \
RETURN_NULL();\
mysqli_object *intern = Z_MYSQLI_P(__id); \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid object or resource %s\n", intern->zo.ce->name->val); \
RETURN_NULL(); \
} \
}
@ -295,22 +297,21 @@ extern PHPAPI zend_class_entry *spl_ce_RuntimeException;
{ \
MYSQLI_FETCH_RESOURCE((__ptr), MY_STMT *, (__id), "mysqli_stmt", (__check)); \
if (!(__ptr)->stmt) { \
mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\
mysqli_object *intern = Z_MYSQLI_P(__id); \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid object or resource %s\n", intern->zo.ce->name); \
RETURN_NULL();\
} \
}
#define MYSQLI_SET_STATUS(__id, __value) \
{ \
mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\
mysqli_object *intern = Z_MYSQLI_P(__id); \
((MYSQLI_RESOURCE *)intern->ptr)->status = __value; \
} \
#define MYSQLI_CLEAR_RESOURCE(__id) \
{ \
mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\
mysqli_object *intern = Z_MYSQLI_P(__id); \
efree(intern->ptr); \
intern->ptr = NULL; \
}

View File

@ -85,7 +85,7 @@ static const zend_function_entry php_recode_functions[] = {
PHP_FE(recode_file, arginfo_recode_file)
PHP_FALIAS(recode, recode_string, arginfo_recode_string)
PHP_FE_END
};
}; /* }}} */
zend_module_entry recode_module_entry = {
STANDARD_MODULE_HEADER,