Browse Source

MFB - Bug #44352 mysqli_connect_error() false negative for host errors

experimental/first_unicode_implementation
Andrey Hristov 18 years ago
parent
commit
e53f44b9bd
  1. 224
      ext/mysqli/mysqli.c
  2. 23
      ext/mysqli/mysqli_api.c
  3. 41
      ext/mysqli/mysqli_driver.c
  4. 19
      ext/mysqli/mysqli_nonapi.c
  5. 138
      ext/mysqli/mysqli_prop.c
  6. 3
      ext/mysqli/mysqli_report.c
  7. 20
      ext/mysqli/mysqli_warning.c
  8. 52
      ext/mysqli/php_mysqli_structs.h
  9. 20
      ext/mysqli/tests/057.phpt
  10. 83
      ext/mysqli/tests/bug34810.phpt
  11. 18
      ext/mysqli/tests/mysqli_class_mysqli_driver_interface.phpt
  12. 56
      ext/mysqli/tests/mysqli_class_mysqli_driver_reflection.phpt
  13. 72
      ext/mysqli/tests/mysqli_class_mysqli_interface.phpt
  14. 156
      ext/mysqli/tests/mysqli_class_mysqli_reflection.phpt
  15. 26
      ext/mysqli/tests/mysqli_class_mysqli_result_interface.phpt
  16. 47
      ext/mysqli/tests/mysqli_class_mysqli_result_reflection.phpt
  17. 42
      ext/mysqli/tests/mysqli_class_mysqli_stmt_interface.phpt
  18. 31
      ext/mysqli/tests/mysqli_class_mysqli_warning_reflection.phpt
  19. 27
      ext/mysqli/tests/mysqli_connect_oo.phpt
  20. 4
      ext/mysqli/tests/mysqli_constants.phpt
  21. 6
      ext/mysqli/tests/mysqli_debug.phpt
  22. 6
      ext/mysqli/tests/mysqli_debug_append.phpt
  23. 6
      ext/mysqli/tests/mysqli_debug_control_string.phpt
  24. 6
      ext/mysqli/tests/mysqli_debug_ini.phpt
  25. 6
      ext/mysqli/tests/mysqli_debug_mysqlnd_control_string.phpt
  26. 6
      ext/mysqli/tests/mysqli_debug_mysqlnd_only.phpt
  27. 38
      ext/mysqli/tests/mysqli_kill.phpt
  28. 23
      ext/mysqli/tests/mysqli_options.phpt
  29. 36
      ext/mysqli/tests/mysqli_real_connect.phpt
  30. 4
      ext/mysqli/tests/mysqli_result_references.phpt
  31. 2
      ext/mysqli/tests/mysqli_stmt_attr_get.phpt
  32. 6
      ext/mysqlnd/mysqlnd_priv.h

224
ext/mysqli/mysqli.c

@ -36,6 +36,27 @@
ZEND_DECLARE_MODULE_GLOBALS(mysqli)
static PHP_GINIT_FUNCTION(mysqli);
#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.s != NULL) { \
zend_declare_property_null((a), (b)[i].name.s, (b)[i].name_length, ZEND_ACC_PUBLIC TSRMLS_CC); \
i++; \
}\
}
static zend_object_handlers mysqli_object_handlers;
static HashTable classes;
static HashTable mysqli_driver_properties;
@ -61,6 +82,8 @@ typedef int (*mysqli_read_t)(mysqli_object *obj, zval **retval 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;
mysqli_read_t read_func;
mysqli_write_t write_func;
} mysqli_prop_handler;
@ -68,7 +91,6 @@ typedef struct _mysqli_prop_handler {
static int le_pmysqli;
/* Destructor for mysqli entries in free_links/used_links */
void php_mysqli_dtor_p_elements(void *data)
{
@ -92,6 +114,7 @@ ZEND_RSRC_DTOR_FUNC(php_mysqli_dtor)
}
}
int php_le_pmysqli(void)
{
return le_pmysqli;
@ -116,7 +139,7 @@ void php_free_stmt_bind_buffer(BIND_BUFFER bbuf, int type)
if (bbuf.vars[i]) {
zval_ptr_dtor(&bbuf.vars[i]);
}
}
}
if (bbuf.vars) {
@ -189,7 +212,7 @@ static void mysqli_objects_free_storage(void *object TSRMLS_DC)
mysqli_object *intern = (mysqli_object *)zo;
MYSQLI_RESOURCE *my_res = (MYSQLI_RESOURCE *)intern->ptr;
my_efree(my_res);
my_efree(my_res);
zend_object_std_dtor(&intern->zo TSRMLS_CC);
efree(intern);
}
@ -363,7 +386,7 @@ void mysqli_write_property(zval *object, zval *member, zval *value TSRMLS_DC)
zend_object_handlers *std_hnd;
int ret;
if (member->type != IS_STRING) {
if (member->type != IS_STRING) {
tmp_member = *member;
zval_copy_ctor(&tmp_member);
convert_to_string(&tmp_member);
@ -393,14 +416,15 @@ void mysqli_write_property(zval *object, zval *member, zval *value TSRMLS_DC)
}
/* }}} */
/* {{{ 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, 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) */
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;
p.name = (char*) pname;
p.name_len = pname_len;
p.read_func = (r_func) ? r_func : mysqli_read_na;
p.write_func = (w_func) ? w_func : mysqli_write_na;
zend_hash_add(h, pname, strlen(pname) + 1, &p, sizeof(mysqli_prop_handler), NULL);
zend_ascii_hash_add(h, pname, pname_len + 1, &p, sizeof(mysqli_prop_handler), NULL);
}
/* }}} */
@ -434,11 +458,95 @@ static union _zend_function *php_mysqli_constructor_get(zval *object TSRMLS_DC)
} else if (obj->zo.ce == mysqli_warning_class_entry) {
f.handler = ZEND_MN(mysqli_warning___construct);
}
return (union _zend_function*)&f;
}
}
static int mysqli_object_has_property(zval *object, zval *member, int has_set_exists TSRMLS_DC) /* {{{ */
{
mysqli_object *obj = (mysqli_object *)zend_objects_get_address(object TSRMLS_CC);
mysqli_prop_handler p;
zval tmp_member;
int ret = 0;
if (member->type != IS_STRING && member->type != IS_UNICODE) {
tmp_member = *member;
zval_copy_ctor(&tmp_member);
convert_to_text(&tmp_member);
member = &tmp_member;
}
if (zend_ascii_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member) + 1, (void **)&p) == SUCCESS) {
switch (has_set_exists) {
case 2:
ret = 1;
break;
case 1: {
zval *value = mysqli_read_property(object, member, BP_VAR_IS TSRMLS_CC);
if (value != EG(uninitialized_zval_ptr)) {
convert_to_boolean(value);
ret = Z_BVAL_P(value)? 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 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);
}
break;
}
default:
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid value for has_set_exists");
}
}
if (member == &tmp_member) {
zval_dtor(member);
}
return ret;
} /* }}} */
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);
HashTable *retval, *props = obj->prop_handler;
HashPosition pos;
mysqli_prop_handler *entry;
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;
zval *value;
INIT_ZVAL(member);
ZVAL_ASCII_STRINGL(&member, entry->name, entry->name_len, 0);
value = mysqli_read_property(object, &member, BP_VAR_IS TSRMLS_CC);
if (value != EG(uninitialized_zval_ptr)) {
Z_ADDREF_P(value);
zend_ascii_hash_add(retval, entry->name, entry->name_len + 1, &value, sizeof(zval *), NULL);
}
zend_hash_move_forward_ex(props, &pos);
if (UG(unicode)) {
zval_dtor(&member);
}
}
*is_temp = 1;
return retval;
}
/* {{{ mysqli_objects_new
*/
PHP_MYSQLI_EXPORT(zend_object_value) mysqli_objects_new(zend_class_entry *class_type TSRMLS_DC)
@ -455,8 +563,8 @@ PHP_MYSQLI_EXPORT(zend_object_value) mysqli_objects_new(zend_class_entry *class_
intern->prop_handler = NULL;
mysqli_base_class = class_type;
while (mysqli_base_class->type != ZEND_INTERNAL_CLASS && mysqli_base_class->parent != NULL)
{
while (mysqli_base_class->type != ZEND_INTERNAL_CLASS &&
mysqli_base_class->parent != NULL) {
mysqli_base_class = mysqli_base_class->parent;
}
@ -566,9 +674,9 @@ static PHP_GINIT_FUNCTION(mysqli)
mysqli_globals->default_pw = NULL;
mysqli_globals->default_socket = NULL;
mysqli_globals->reconnect = 0;
mysqli_globals->allow_local_infile = 1;
mysqli_globals->report_mode = 0;
mysqli_globals->report_ht = 0;
mysqli_globals->allow_local_infile = 1;
#ifdef HAVE_EMBEDDED_MYSQLI
mysqli_globals->embedded = 1;
#else
@ -589,7 +697,6 @@ PHP_MINIT_FUNCTION(mysqli)
zend_object_handlers *std_hnd = zend_get_std_object_handlers();
REGISTER_INI_ENTRIES();
#ifndef MYSQLI_USE_MYSQLND
#if MYSQL_VERSION_ID >= 40000
if (mysql_server_init(0, NULL, NULL)) {
@ -607,6 +714,8 @@ PHP_MINIT_FUNCTION(mysqli)
mysqli_object_handlers.write_property = mysqli_write_property;
mysqli_object_handlers.get_property_ptr_ptr = std_hnd->get_property_ptr_ptr;
mysqli_object_handlers.get_constructor = php_mysqli_constructor_get;
mysqli_object_handlers.has_property = mysqli_object_has_property;
mysqli_object_handlers.get_debug_info = mysqli_object_get_debug_info;
zend_u_hash_init(&classes, 0, NULL, NULL, 1, 1);
@ -628,6 +737,7 @@ PHP_MINIT_FUNCTION(mysqli)
ce = mysqli_driver_class_entry;
zend_u_hash_init(&mysqli_driver_properties, 0, NULL, NULL, 1, 1);
MYSQLI_ADD_PROPERTIES(&mysqli_driver_properties, mysqli_driver_property_entries);
MYSQLI_ADD_PROPERTIES_INFO(ce, mysqli_driver_property_info_entries);
zend_u_hash_add(&classes, ZEND_STR_TYPE, ce->name, ce->name_length+1, &mysqli_driver_properties, sizeof(mysqli_driver_properties), NULL);
ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
@ -635,6 +745,7 @@ PHP_MINIT_FUNCTION(mysqli)
ce = mysqli_link_class_entry;
zend_u_hash_init(&mysqli_link_properties, 0, NULL, NULL, 1, 1);
MYSQLI_ADD_PROPERTIES(&mysqli_link_properties, mysqli_link_property_entries);
MYSQLI_ADD_PROPERTIES_INFO(ce, mysqli_link_property_info_entries);
zend_u_hash_add(&classes, ZEND_STR_TYPE, ce->name, ce->name_length+1, &mysqli_link_properties, sizeof(mysqli_link_properties), NULL);
REGISTER_MYSQLI_CLASS_ENTRY("mysqli_warning", mysqli_warning_class_entry, mysqli_warning_methods);
@ -642,18 +753,21 @@ PHP_MINIT_FUNCTION(mysqli)
ce->ce_flags |= ZEND_ACC_FINAL_CLASS | ZEND_ACC_PROTECTED;
zend_u_hash_init(&mysqli_warning_properties, 0, NULL, NULL, 1, 1);
MYSQLI_ADD_PROPERTIES(&mysqli_warning_properties, mysqli_warning_property_entries);
MYSQLI_ADD_PROPERTIES_INFO(ce, mysqli_warning_property_info_entries);
zend_u_hash_add(&classes, ZEND_STR_TYPE, ce->name, ce->name_length+1, &mysqli_warning_properties, sizeof(mysqli_warning_properties), NULL);
REGISTER_MYSQLI_CLASS_ENTRY("mysqli_result", mysqli_result_class_entry, mysqli_result_methods);
ce = mysqli_result_class_entry;
zend_u_hash_init(&mysqli_result_properties, 0, NULL, NULL, 1, 1);
MYSQLI_ADD_PROPERTIES(&mysqli_result_properties, mysqli_result_property_entries);
MYSQLI_ADD_PROPERTIES_INFO(ce, mysqli_result_property_info_entries);
zend_u_hash_add(&classes, ZEND_STR_TYPE, ce->name, ce->name_length+1, &mysqli_result_properties, sizeof(mysqli_result_properties), NULL);
REGISTER_MYSQLI_CLASS_ENTRY("mysqli_stmt", mysqli_stmt_class_entry, mysqli_stmt_methods);
ce = mysqli_stmt_class_entry;
zend_u_hash_init(&mysqli_stmt_properties, 0, NULL, NULL, 1, 1);
MYSQLI_ADD_PROPERTIES(&mysqli_stmt_properties, mysqli_stmt_property_entries);
MYSQLI_ADD_PROPERTIES_INFO(ce, mysqli_stmt_property_info_entries);
zend_u_hash_add(&classes, ZEND_STR_TYPE, ce->name, ce->name_length+1, &mysqli_stmt_properties, sizeof(mysqli_stmt_properties), NULL);
@ -852,6 +966,8 @@ PHP_RINIT_FUNCTION(mysqli)
*/
PHP_RSHUTDOWN_FUNCTION(mysqli)
{
/* check persistent connections, move used to free */
#if !defined(MYSQLI_USE_MYSQLND) && defined(ZTS) && MYSQL_VERSION_ID >= 40000
mysql_thread_end();
#endif
@ -877,16 +993,16 @@ PHP_MINFO_FUNCTION(mysqli)
php_info_print_table_start();
php_info_print_table_header(2, "MysqlI Support", "enabled");
php_info_print_table_row(2, "Client API library version", mysql_get_client_info());
#if !defined(MYSQLI_USE_MYSQLND)
php_info_print_table_row(2, "Client API header version", MYSQL_SERVER_VERSION);
php_info_print_table_row(2, "MYSQLI_SOCKET", MYSQL_UNIX_ADDR);
#else
snprintf(buf, sizeof(buf), "%ld", MyG(num_active_persistent));
php_info_print_table_row(2, "Active Persistent Links", buf);
snprintf(buf, sizeof(buf), "%ld", MyG(num_inactive_persistent));
php_info_print_table_row(2, "Inactive Persistent Links", buf);
snprintf(buf, sizeof(buf), "%ld", MyG(num_links));
php_info_print_table_row(2, "Active Links", buf);
#if !defined(MYSQLI_USE_MYSQLND)
php_info_print_table_row(2, "Client API header version", MYSQL_SERVER_VERSION);
php_info_print_table_row(2, "MYSQLI_SOCKET", MYSQL_UNIX_ADDR);
#else
{
zval values;
@ -912,12 +1028,12 @@ Parameters:
object -> mysqli_stmt_init
object, query -> mysqli_prepare
*/
ZEND_FUNCTION(mysqli_stmt_construct)
PHP_FUNCTION(mysqli_stmt_construct)
{
MY_MYSQL *mysql;
zval *mysql_link;
zval *mysql_link;
MY_STMT *stmt;
MYSQLI_RESOURCE *mysqli_resource;
MYSQLI_RESOURCE *mysqli_resource;
char *statement;
int statement_len;
@ -968,12 +1084,12 @@ constructor for result object.
Parameters:
object [, mode] -> mysqli_store/use_result
*/
ZEND_FUNCTION(mysqli_result_construct)
PHP_FUNCTION(mysqli_result_construct)
{
MY_MYSQL *mysql;
MYSQL_RES *result = NULL;
zval *mysql_link;
MYSQLI_RESOURCE *mysqli_resource;
MYSQLI_RESOURCE *mysqli_resource;
long resmode = MYSQLI_STORE_RESULT;
switch (ZEND_NUM_ARGS()) {
@ -1018,6 +1134,7 @@ ZEND_FUNCTION(mysqli_result_construct)
mysqli_resource->status = MYSQLI_STATUS_VALID;
((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->ptr = mysqli_resource;
}
/* }}} */
@ -1089,6 +1206,11 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
RETURN_NULL();
}
/*
It's needed to call fetch_fields because we need info whether
the field is binary. In 5_3 this is not needed as the latter
doesn't know about Unicode.
*/
fields = mysql_fetch_fields(result);
array_init(return_value);
@ -1215,21 +1337,9 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
}
/* }}} */
/* {{{ php_mysqli_set_error
*/
PHP_MYSQLI_API void php_mysqli_set_error(long mysql_errno, char *mysql_err TSRMLS_DC)
{
MyG(error_no) = mysql_errno;
if (MyG(error_msg)) {
efree(MyG(error_msg));
}
MyG(error_msg) = estrdup(mysql_err);
}
/* }}} */
#if !defined(MYSQLI_USE_MYSQLND)
#define ALLOC_CALLBACK_ARGS(a, b, c)\
if (c) {\
a = (zval ***)safe_emalloc(c, sizeof(zval **), 0);\
@ -1249,27 +1359,14 @@ if (a) {\
}
#define LOCAL_INFILE_ERROR_MSG(source,dest)\
memset(source, 0, LOCAL_INFILE_ERROR_LEN);\
memcpy(source, dest, MIN(strlen(dest), LOCAL_INFILE_ERROR_LEN-1));\
php_error_docref(NULL TSRMLS_CC, E_WARNING, dest);
memset(source, 0, LOCAL_INFILE_ERROR_LEN);\
memcpy(source, dest, MIN(strlen(dest), LOCAL_INFILE_ERROR_LEN-1));\
php_error_docref(NULL TSRMLS_CC, E_WARNING, dest);
/* {{{ void php_set_local_infile_handler_default
*/
void php_set_local_infile_handler_default(MY_MYSQL *mysql) {
/* register internal callback functions */
mysql_set_local_infile_handler(mysql->mysql, &php_local_infile_init, &php_local_infile_read,
&php_local_infile_end, &php_local_infile_error, (void *)mysql);
if (mysql->li_read) {
zval_ptr_dtor(&mysql->li_read);
mysql->li_read = NULL;
}
}
/* }}} */
/* {{{ php_local_infile_init
*/
int php_local_infile_init(void **ptr, const char *filename, void *userdata)
static int php_local_infile_init(void **ptr, const char *filename, void *userdata)
{
mysqli_local_infile *data;
MY_MYSQL *mysql;
@ -1309,7 +1406,7 @@ int php_local_infile_init(void **ptr, const char *filename, void *userdata)
/* }}} */
/* {{{ int php_local_infile_read */
int php_local_infile_read(void *ptr, char *buf, uint buf_len)
static int php_local_infile_read(void *ptr, char *buf, uint buf_len)
{
mysqli_local_infile *data;
MY_MYSQL *mysql;
@ -1327,7 +1424,7 @@ int php_local_infile_read(void *ptr, char *buf, uint buf_len)
/* default processing */
if (!mysql->li_read) {
int count= (int)php_stream_read(mysql->li_stream, buf, buf_len);
int count = (int)php_stream_read(mysql->li_stream, buf, buf_len);
if (count < 0) {
LOCAL_INFILE_ERROR_MSG(data->error_msg, ER(2));
@ -1337,7 +1434,7 @@ int php_local_infile_read(void *ptr, char *buf, uint buf_len)
}
ALLOC_CALLBACK_ARGS(callback_args, 1, argc);
/* set parameters: filepointer, buffer, buffer_len, errormsg */
MAKE_STD_ZVAL(fp);
@ -1398,7 +1495,7 @@ int php_local_infile_read(void *ptr, char *buf, uint buf_len)
/* {{{ php_local_infile_error
*/
int php_local_infile_error(void *ptr, char *error_msg, uint error_msg_len)
static int php_local_infile_error(void *ptr, char *error_msg, uint error_msg_len)
{
mysqli_local_infile *data = (mysqli_local_infile *) ptr;
@ -1413,7 +1510,7 @@ int php_local_infile_error(void *ptr, char *error_msg, uint error_msg_len)
/* {{{ php_local_infile_end
*/
void php_local_infile_end(void *ptr)
static void php_local_infile_end(void *ptr)
{
mysqli_local_infile *data;
MY_MYSQL *mysql;
@ -1428,6 +1525,7 @@ void php_local_infile_end(void *ptr)
}
return;
}
if (mysql->li_stream) {
php_stream_close(mysql->li_stream);
}
@ -1435,6 +1533,20 @@ void php_local_infile_end(void *ptr)
return;
}
/* }}} */
/* {{{ void php_set_local_infile_handler_default
*/
void php_set_local_infile_handler_default(MY_MYSQL *mysql) {
/* register internal callback functions */
mysql_set_local_infile_handler(mysql->mysql, &php_local_infile_init, &php_local_infile_read,
&php_local_infile_end, &php_local_infile_error, (void *)mysql);
if (mysql->li_read) {
zval_ptr_dtor(&mysql->li_read);
mysql->li_read = NULL;
}
}
/* }}} */
#endif
/*

23
ext/mysqli/mysqli_api.c

@ -430,7 +430,7 @@ mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval ***args, unsigned int argc,
stmt->result.vars = (zval **)safe_emalloc((var_cnt), sizeof(zval), 0);
for (i = start; i < var_cnt+start; i++) {
ofs = i-start;
Z_ADDREF_P(*args[i]);
Z_ADDREF_PP(args[i]);
stmt->result.vars[ofs] = *args[i];
}
}
@ -562,7 +562,6 @@ PHP_FUNCTION(mysqli_close)
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_INITIALIZED);
if (!mysql->persistent) {
mysqli_close(mysql->mysql, MYSQLI_CLOSE_EXPLICIT);
mysql->mysql = NULL;
@ -582,7 +581,7 @@ PHP_FUNCTION(mysqli_close)
php_clear_mysql(mysql);
MYSQLI_CLEAR_RESOURCE(&mysql_link);
MYSQLI_CLEAR_RESOURCE(&mysql_link);
efree(mysql);
RETURN_TRUE;
}
@ -686,7 +685,7 @@ PHP_FUNCTION(mysqli_errno)
Returns the text of the error message from previous MySQL operation */
PHP_FUNCTION(mysqli_error)
{
MY_MYSQL *mysql;
MY_MYSQL *mysql;
zval *mysql_link;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
@ -703,7 +702,7 @@ PHP_FUNCTION(mysqli_error)
PHP_FUNCTION(mysqli_stmt_execute)
{
MY_STMT *stmt;
zval *mysql_stmt;
zval *mysql_stmt;
#ifndef MYSQLI_USE_MYSQLND
unsigned int i;
#endif
@ -798,7 +797,7 @@ void mysqli_stmt_fetch_libmysql(INTERNAL_FUNCTION_PARAMETERS)
MY_STMT *stmt;
zval *mysql_stmt;
unsigned int i;
ulong ret;
ulong ret;
unsigned int uval;
my_ulonglong llval;
MYSQL_RES *result_metadata = NULL;
@ -1041,9 +1040,9 @@ PHP_FUNCTION(mysqli_fetch_field)
PHP_FUNCTION(mysqli_fetch_fields)
{
MYSQL_RES *result;
zval *mysql_result;
zval *mysql_result;
MYSQL_FIELD *field;
zval *obj;
zval *obj;
unsigned int i;
@ -1220,9 +1219,7 @@ PHP_FUNCTION(mysqli_free_result)
Get MySQL client info */
PHP_FUNCTION(mysqli_get_client_info)
{
char *info = (char *)mysql_get_client_info();
RETURN_UTF8_STRING(info, ZSTR_DUPLICATE);
RETURN_UTF8_STRING((char *)mysql_get_client_info(), ZSTR_DUPLICATE);
}
/* }}} */
@ -1236,7 +1233,7 @@ PHP_FUNCTION(mysqli_get_client_version)
/* {{{ proto string mysqli_get_host_info (object link) U
Get MySQL host info */
PHP_FUNCTION(mysqli_get_host_info)
PHP_FUNCTION(mysqli_get_host_info)
{
MY_MYSQL *mysql;
zval *mysql_link = NULL;
@ -1246,7 +1243,7 @@ PHP_FUNCTION(mysqli_get_host_info)
}
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
RETURN_UTF8_STRING(mysql->mysql->host_info, ZSTR_DUPLICATE);
RETURN_UTF8_STRING((mysql->mysql->host_info) ? mysql->mysql->host_info : "", ZSTR_DUPLICATE);
}
/* }}} */

41
ext/mysqli/mysqli_driver.c

@ -36,7 +36,7 @@
#define MAP_PROPERTY_MYG_BOOL_READ(name, value) \
static int name(mysqli_object *obj, zval **retval TSRMLS_DC) \
{ \
ALLOC_ZVAL(*retval); \
MAKE_STD_ZVAL(*retval); \
ZVAL_BOOL(*retval, MyG(value)); \
return SUCCESS; \
} \
@ -51,7 +51,7 @@ 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) \
{ \
ALLOC_ZVAL(*retval); \
MAKE_STD_ZVAL(*retval); \
ZVAL_LONG(*retval, MyG(value)); \
return SUCCESS; \
} \
@ -66,7 +66,7 @@ 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) \
{ \
ALLOC_ZVAL(*retval); \
MAKE_STD_ZVAL(*retval); \
ZVAL_STRING(*retval, MyG(value), 1); \
return SUCCESS; \
} \
@ -91,7 +91,7 @@ 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)
{
ALLOC_ZVAL(*retval);
MAKE_STD_ZVAL(*retval);
#ifdef HAVE_EMBEDDED_MYSQLI
ZVAL_BOOL(*retval, 1);
#else
@ -104,7 +104,7 @@ static int driver_embedded_read(mysqli_object *obj, zval **retval TSRMLS_DC)
/* {{{ property driver_client_version_read */
static int driver_client_version_read(mysqli_object *obj, zval **retval TSRMLS_DC)
{
ALLOC_ZVAL(*retval);
MAKE_STD_ZVAL(*retval);
ZVAL_LONG(*retval, MYSQL_VERSION_ID);
return SUCCESS;
}
@ -113,7 +113,7 @@ static int driver_client_version_read(mysqli_object *obj, zval **retval TSRMLS_D
/* {{{ property driver_client_info_read */
static int driver_client_info_read(mysqli_object *obj, zval **retval TSRMLS_DC)
{
ALLOC_ZVAL(*retval);
MAKE_STD_ZVAL(*retval);
ZVAL_RT_STRING(*retval, (char *)mysql_get_client_info(), 1);
return SUCCESS;
}
@ -122,7 +122,7 @@ static int driver_client_info_read(mysqli_object *obj, zval **retval TSRMLS_DC)
/* {{{ property driver_driver_version_read */
static int driver_driver_version_read(mysqli_object *obj, zval **retval TSRMLS_DC)
{
ALLOC_ZVAL(*retval);
MAKE_STD_ZVAL(*retval);
ZVAL_LONG(*retval, MYSQLI_VERSION_ID);
return SUCCESS;
}
@ -143,14 +143,27 @@ ZEND_FUNCTION(mysqli_driver_construct)
}
const mysqli_property_entry mysqli_driver_property_entries[] = {
{"client_info", driver_client_info_read, NULL},
{"client_version", driver_client_version_read, NULL},
{"driver_version", driver_driver_version_read, NULL},
{"embedded", driver_embedded_read, NULL},
{"reconnect", driver_reconnect_read, driver_reconnect_write},
{"report_mode", driver_report_read, driver_report_write},
{NULL, NULL, NULL}
{"client_info", sizeof("client_info") - 1, driver_client_info_read, NULL},
{"client_version", sizeof("client_version") - 1, driver_client_version_read, NULL},
{"driver_version", sizeof("driver_version") - 1, driver_driver_version_read, NULL},
{"embedded", sizeof("embedded") - 1, driver_embedded_read, NULL},
{"reconnect", sizeof("reconnect") - 1, driver_reconnect_read, driver_reconnect_write},
{"report_mode", sizeof("report_mode") - 1, driver_report_read, driver_report_write},
{NULL, 0, NULL, NULL}
};
/* {{{ mysqli_warning_property_info_entries */
zend_property_info mysqli_driver_property_info_entries[] = {
{ZEND_ACC_PUBLIC, {"client_info"}, sizeof("client_info") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"client_version"},sizeof("client_version") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"driver_version"},sizeof("driver_version") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"embedded"}, sizeof("embedded") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"reconnect"}, sizeof("reconnect") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"report_mode"}, sizeof("report_mode") - 1, 0, {NULL}, 0, NULL},
{0, {NULL}, 0, 0, {NULL}, 0, NULL},
};
/* }}} */
/* {{{ mysqli_driver_methods[]
*/

19
ext/mysqli/mysqli_nonapi.c

@ -33,6 +33,19 @@
#define SAFE_STR(a) ((a)?a:"")
/* {{{ php_mysqli_set_error
*/
static void php_mysqli_set_error(long mysql_errno, char *mysql_err TSRMLS_DC)
{
MyG(error_no) = mysql_errno;
if (MyG(error_msg)) {
efree(MyG(error_msg));
}
MyG(error_msg) = estrdup(mysql_err);
}
/* }}} */
void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_connect, zend_bool in_ctor)
{
MY_MYSQL *mysql = NULL;
@ -92,7 +105,7 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
/* remove some insecure options */
flags &= ~CLIENT_MULTI_STATEMENTS; /* don't allow multi_queries via connect parameter */
if (PG(open_basedir) && PG(open_basedir)[0] != '\0') {
flags ^= CLIENT_LOCAL_FILES;
flags &= ~CLIENT_LOCAL_FILES;
}
}
@ -220,7 +233,7 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
port, socket, flags, MyG(mysqlnd_thd_zval_cache) TSRMLS_CC) == NULL)
#endif
{
/* Save error messages */
/* Save error messages - for mysqli_connect_error() & mysqli_connect_errno() */
php_mysqli_set_error(mysql_errno(mysql->mysql), (char *) mysql_error(mysql->mysql) TSRMLS_CC);
php_mysqli_throw_sql_exception((char *)mysql_sqlstate(mysql->mysql), mysql_errno(mysql->mysql) TSRMLS_CC,
"%s", mysql_error(mysql->mysql));
@ -630,7 +643,7 @@ PHP_FUNCTION(mysqli_get_warnings)
}
/* }}} */
/* {{{ proto object mysqli_stmt_get_warnings(object link) U */
/* {{{ proto object mysqli_stmt_get_warnings(object link) U */
PHP_FUNCTION(mysqli_stmt_get_warnings)
{
MY_STMT *stmt;

138
ext/mysqli/mysqli_prop.c

@ -40,7 +40,7 @@
#define MYSQLI_GET_MYSQL(statusval) \
MYSQL *p; \
ALLOC_ZVAL(*retval);\
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 %v", obj->zo.ce->name);\
ZVAL_NULL(*retval);\
@ -52,7 +52,7 @@ if (!obj->ptr || !(MY_MYSQL *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr) { \
#define MYSQLI_GET_RESULT(statusval) \
MYSQL_RES *p; \
ALLOC_ZVAL(*retval);\
MAKE_STD_ZVAL(*retval);\
if (!obj->ptr) { \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %v", obj->zo.ce->name);\
ZVAL_NULL(*retval);\
@ -65,7 +65,7 @@ if (!obj->ptr) { \
#define MYSQLI_GET_STMT(statusval) \
MYSQL_STMT *p; \
ALLOC_ZVAL(*retval);\
MAKE_STD_ZVAL(*retval);\
if (!obj->ptr) { \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %v", obj->zo.ce->name);\
ZVAL_NULL(*retval);\
@ -116,7 +116,7 @@ static int __func(mysqli_object *obj, zval **retval TSRMLS_DC)\
/* {{{ property link_client_version_read */
static int link_client_version_read(mysqli_object *obj, zval **retval TSRMLS_DC)
{
ALLOC_ZVAL(*retval);
MAKE_STD_ZVAL(*retval);
ZVAL_LONG(*retval, MYSQL_VERSION_ID);
return SUCCESS;
}
@ -125,7 +125,7 @@ static int link_client_version_read(mysqli_object *obj, zval **retval TSRMLS_DC)
/* {{{ property link_client_info_read */
static int link_client_info_read(mysqli_object *obj, zval **retval TSRMLS_DC)
{
ALLOC_ZVAL(*retval);
MAKE_STD_ZVAL(*retval);
CHECK_STATUS(MYSQLI_STATUS_INITIALIZED);
ZVAL_UTF8_STRING(*retval, MYSQL_SERVER_VERSION, ZSTR_DUPLICATE)
return SUCCESS;
@ -135,7 +135,7 @@ static int link_client_info_read(mysqli_object *obj, zval **retval TSRMLS_DC)
/* {{{ property link_connect_errno_read */
static int link_connect_errno_read(mysqli_object *obj, zval **retval TSRMLS_DC)
{
ALLOC_ZVAL(*retval);
MAKE_STD_ZVAL(*retval);
CHECK_STATUS(MYSQLI_STATUS_INITIALIZED);
ZVAL_LONG(*retval, (long)MyG(error_no));
return SUCCESS;
@ -145,7 +145,7 @@ static int link_connect_errno_read(mysqli_object *obj, zval **retval TSRMLS_DC)
/* {{{ property link_connect_error_read */
static int link_connect_error_read(mysqli_object *obj, zval **retval TSRMLS_DC)
{
ALLOC_ZVAL(*retval);
MAKE_STD_ZVAL(*retval);
CHECK_STATUS(MYSQLI_STATUS_INITIALIZED);
ZVAL_UTF8_STRING(*retval, MyG(error_msg), ZSTR_DUPLICATE)
return SUCCESS;
@ -158,7 +158,7 @@ static int link_affected_rows_read(mysqli_object *obj, zval **retval TSRMLS_DC)
MY_MYSQL *mysql;
my_ulonglong rc;
ALLOC_ZVAL(*retval);
MAKE_STD_ZVAL(*retval);
mysql = (MY_MYSQL *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;
@ -206,7 +206,7 @@ static int result_type_read(mysqli_object *obj, zval **retval TSRMLS_DC)
{
MYSQL_RES *p;
ALLOC_ZVAL(*retval);
MAKE_STD_ZVAL(*retval);
CHECK_STATUS(MYSQLI_STATUS_VALID);
p = (MYSQL_RES *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;
@ -225,7 +225,7 @@ static int result_lengths_read(mysqli_object *obj, zval **retval TSRMLS_DC)
MYSQL_RES *p;
ulong *ret;
ALLOC_ZVAL(*retval);
MAKE_STD_ZVAL(*retval);
CHECK_STATUS(MYSQLI_STATUS_VALID);
p = (MYSQL_RES *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;
@ -257,7 +257,7 @@ static int stmt_id_read(mysqli_object *obj, zval **retval TSRMLS_DC)
{
MY_STMT *p;
ALLOC_ZVAL(*retval);
MAKE_STD_ZVAL(*retval);
CHECK_STATUS(MYSQLI_STATUS_VALID);
p = (MY_STMT*)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;
@ -277,7 +277,7 @@ static int stmt_affected_rows_read(mysqli_object *obj, zval **retval TSRMLS_DC)
MY_STMT *p;
my_ulonglong rc;
ALLOC_ZVAL(*retval);
MAKE_STD_ZVAL(*retval);
CHECK_STATUS(MYSQLI_STATUS_VALID);
p = (MY_STMT *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;
@ -314,46 +314,92 @@ MYSQLI_MAP_PROPERTY_FUNC_STRING(stmt_sqlstate_read, mysql_stmt_sqlstate, MYSQLI_
/* }}} */
const mysqli_property_entry mysqli_link_property_entries[] = {
{"affected_rows", link_affected_rows_read, NULL},
{"client_info", link_client_info_read, NULL},
{"client_version", link_client_version_read, NULL},
{"connect_errno", link_connect_errno_read, NULL},
{"connect_error", link_connect_error_read, NULL},
{"errno", link_errno_read, NULL},
{"error", link_error_read, NULL},
{"field_count", link_field_count_read, NULL},
{"host_info", link_host_info_read, NULL},
{"info", link_info_read, NULL},
{"insert_id", link_insert_id_read, NULL},
{"server_info", link_server_info_read, NULL},
{"server_version", link_server_version_read, NULL},
{"sqlstate", link_sqlstate_read, NULL},
{"protocol_version", link_protocol_version_read, NULL},
{"thread_id", link_thread_id_read, NULL},
{"warning_count", link_warning_count_read, NULL},
{NULL, NULL, NULL}
{"affected_rows", sizeof("affected_rows") - 1, link_affected_rows_read, NULL},
{"client_info", sizeof("client_info") - 1, link_client_info_read, NULL},
{"client_version", sizeof("client_version") - 1, link_client_version_read, NULL},
{"connect_errno", sizeof("connect_errno") - 1, link_connect_errno_read, NULL},
{"connect_error", sizeof("connect_error") - 1, link_connect_error_read, NULL},
{"errno", sizeof("errno") - 1, link_errno_read, NULL},
{"error", sizeof("error") - 1, link_error_read, NULL},
{"field_count", sizeof("field_count") - 1, link_field_count_read, NULL},
{"host_info", sizeof("host_info") - 1, link_host_info_read, NULL},
{"info", sizeof("info") - 1, link_info_read, NULL},
{"insert_id", sizeof("insert_id") - 1, link_insert_id_read, NULL},
{"server_info", sizeof("server_info") - 1, link_server_info_read, NULL},
{"server_version", sizeof("server_version") - 1, link_server_version_read, NULL},
{"sqlstate", sizeof("sqlstate") - 1, link_sqlstate_read, NULL},
{"protocol_version",sizeof("protocol_version") - 1, link_protocol_version_read, NULL},
{"thread_id", sizeof("thread_id") - 1, link_thread_id_read, NULL},
{"warning_count", sizeof("warning_count") - 1, link_warning_count_read, NULL},
{NULL, 0, NULL, NULL}
};
/* should not be const, as it is patched during runtime */
zend_property_info mysqli_link_property_info_entries[] = {
{ZEND_ACC_PUBLIC, {"affected_rows"},sizeof("affected_rows") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"client_info"}, sizeof("client_info") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"client_version"},sizeof("client_version") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"connect_errno"},sizeof("connect_errno") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"connect_error"},sizeof("connect_error") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"errno"}, sizeof("errno") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"error"}, sizeof("error") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"field_count"}, sizeof("field_count") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"host_info"}, sizeof("host_info") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"info"}, sizeof("info") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"insert_id"}, sizeof("insert_id") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"server_info"}, sizeof("server_info") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"server_version"},sizeof("server_version") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"sqlstate"}, sizeof("sqlstate") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"protocol_version"}, sizeof("protocol_version")-1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"thread_id"}, sizeof("thread_id") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"warning_count"},sizeof("warning_count") - 1, 0, {NULL}, 0, NULL},
{0, {NULL}, 0, 0, {NULL}, 0, NULL}
};
const mysqli_property_entry mysqli_result_property_entries[] = {
{"current_field", result_current_field_read, NULL},
{"field_count", result_field_count_read, NULL},
{"lengths", result_lengths_read, NULL},
{"num_rows", result_num_rows_read, NULL},
{"type", result_type_read, NULL},
{NULL, NULL, NULL}
{"current_field",sizeof("current_field")-1, result_current_field_read, NULL},
{"field_count", sizeof("field_count") - 1, result_field_count_read, NULL},
{"lengths", sizeof("lengths") - 1, result_lengths_read, NULL},
{"num_rows", sizeof("num_rows") - 1, result_num_rows_read, NULL},
{"type", sizeof("type") - 1, result_type_read, NULL},
{NULL, 0, NULL, NULL}
};
zend_property_info mysqli_result_property_info_entries[] = {
{ZEND_ACC_PUBLIC, {"current_field"},sizeof("current_field")-1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"field_count"}, sizeof("field_count") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"lengths"}, sizeof("lengths") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"num_rows"}, sizeof("num_rows") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"type"}, sizeof("type") - 1, 0, {NULL}, 0, NULL},
{0, {NULL}, 0, 0, {NULL}, 0, NULL}
};
const mysqli_property_entry mysqli_stmt_property_entries[] = {
{"affected_rows", stmt_affected_rows_read, NULL},
{"insert_id", stmt_insert_id_read, NULL},
{"num_rows", stmt_num_rows_read, NULL},
{"param_count", stmt_param_count_read, NULL},
{"field_count", stmt_field_count_read, NULL},
{"errno", stmt_errno_read, NULL},
{"error", stmt_error_read, NULL},
{"sqlstate", stmt_sqlstate_read, NULL},
{"id", stmt_id_read, NULL},
{NULL, NULL, NULL}
{"affected_rows", sizeof("affected_rows")-1,stmt_affected_rows_read, NULL},
{"insert_id", sizeof("insert_id") - 1, stmt_insert_id_read, NULL},
{"num_rows", sizeof("num_rows") - 1, stmt_num_rows_read, NULL},
{"param_count", sizeof("param_count") - 1, stmt_param_count_read, NULL},
{"field_count", sizeof("field_count") - 1, stmt_field_count_read, NULL},
{"errno", sizeof("errno") - 1, stmt_errno_read, NULL},
{"error", sizeof("error") - 1, stmt_error_read, NULL},
{"sqlstate", sizeof("sqlstate") - 1, stmt_sqlstate_read, NULL},
{"id", sizeof("id") - 1, stmt_id_read, NULL},
{NULL, 0, NULL, NULL}
};
zend_property_info mysqli_stmt_property_info_entries[] = {
{ZEND_ACC_PUBLIC, {"affected_rows"},sizeof("affected_rows") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"insert_id"}, sizeof("insert_id") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"num_rows"}, sizeof("num_rows") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"param_count"}, sizeof("param_count") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"field_count"}, sizeof("field_count") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"errno"}, sizeof("errno") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"error"}, sizeof("error") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"sqlstate"}, sizeof("sqlstate") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"id"}, sizeof("id") - 1, 0, {NULL}, 0, NULL},
{0, {NULL}, 0, 0, {NULL}, 0, NULL}
};
/*

3
ext/mysqli/mysqli_report.c

@ -47,7 +47,8 @@ PHP_FUNCTION(mysqli_report)
/* }}} */
/* {{{ void php_mysqli_report_error(char *sqlstate, int errorno, char *error) */
void php_mysqli_report_error(const char *sqlstate, int errorno, const char *error TSRMLS_DC) {
void php_mysqli_report_error(const char *sqlstate, int errorno, const char *error TSRMLS_DC)
{
php_mysqli_throw_sql_exception((char *)sqlstate, errorno TSRMLS_CC, "%s", error);
}
/* }}} */

20
ext/mysqli/mysqli_warning.c

@ -140,7 +140,7 @@ MYSQLI_WARNING *php_get_warnings(MYSQL *mysql TSRMLS_DC)
int errno;
MAKE_STD_ZVAL(row);
mysqlnd_fetch_into(result, MYSQLND_FETCH_NUM, row, MYSQLND_MYSQL);
mysqlnd_fetch_into(result, MYSQLND_FETCH_NUM, row, MYSQLND_MYSQLI);
if (Z_TYPE_P(row) != IS_ARRAY) {
zval_ptr_dtor(&row);
break;
@ -322,13 +322,23 @@ const zend_function_entry mysqli_warning_methods[] = {
/* {{{ mysqli_warning_property_entries */
const mysqli_property_entry mysqli_warning_property_entries[] = {
{"message", mysqli_warning_message, NULL},
{"sqlstate", mysqli_warning_sqlstate, NULL},
{"errno", mysqli_warning_errno, NULL},
{NULL, NULL, NULL}
{"message", sizeof("message") - 1, mysqli_warning_message, NULL},
{"sqlstate", sizeof("sqlstate") - 1, mysqli_warning_sqlstate, NULL},
{"errno", sizeof("errno") - 1, mysqli_warning_errno, NULL},
{NULL, 0, NULL, NULL}
};
/* }}} */
/* {{{ mysqli_warning_property_info_entries */
zend_property_info mysqli_warning_property_info_entries[] = {
{ZEND_ACC_PUBLIC, {"message"}, sizeof("message") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"sqlstate"}, sizeof("sqlstate") - 1, 0, {NULL}, 0, NULL},
{ZEND_ACC_PUBLIC, {"errno"}, sizeof("errno") - 1, 0, {NULL}, 0, NULL},
{0, {NULL}, 0, 0, {NULL}, 0, NULL}
};
/* }}} */
/*
* Local variables:
* tab-width: 4

52
ext/mysqli/php_mysqli_structs.h

@ -134,7 +134,8 @@ struct st_mysqli_warning {
};
typedef struct _mysqli_property_entry {
char *pname;
const char *pname;
size_t pname_length;
int (*r_func)(mysqli_object *obj, zval **retval TSRMLS_DC);
int (*w_func)(mysqli_object *obj, zval *value TSRMLS_DC);
} mysqli_property_entry;
@ -188,6 +189,12 @@ extern const mysqli_property_entry mysqli_stmt_property_entries[];
extern const mysqli_property_entry mysqli_driver_property_entries[];
extern const mysqli_property_entry mysqli_warning_property_entries[];
extern zend_property_info mysqli_link_property_info_entries[];
extern zend_property_info mysqli_result_property_info_entries[];
extern zend_property_info mysqli_stmt_property_info_entries[];
extern zend_property_info mysqli_driver_property_info_entries[];
extern zend_property_info mysqli_warning_property_info_entries[];
#ifdef MYSQLI_USE_MYSQLND
extern MYSQLND_ZVAL_PCACHE *mysqli_mysqlnd_zval_cache;
extern MYSQLND_QCACHE *mysqli_mysqlnd_qcache;
@ -201,10 +208,6 @@ extern void php_clear_warnings(MYSQLI_WARNING *w);
extern void php_free_stmt_bind_buffer(BIND_BUFFER bbuf, int type);
extern void php_mysqli_report_error(const char *sqlstate, int errorno, const char *error TSRMLS_DC);
extern void php_mysqli_report_index(const char *query, unsigned int status TSRMLS_DC);
extern int php_local_infile_init(void **, const char *, void *);
extern int php_local_infile_read(void *, char *, uint);
extern void php_local_infile_end(void *);
extern int php_local_infile_error(void *, char *, uint);
extern void php_set_local_infile_handler_default(MY_MYSQL *);
extern void php_mysqli_throw_sql_exception(char *sqlstate, int errorno TSRMLS_DC, char *format, ...);
extern zend_class_entry *mysqli_link_class_entry;
@ -298,24 +301,9 @@ PHP_MYSQLI_EXPORT(zend_object_value) mysqli_objects_new(zend_class_entry * TSRML
} \
}
#define MYSQLI_ADD_PROPERTIES(a,b) \
{ \
int i = 0; \
while (b[i].pname != NULL) { \
mysqli_add_property(a, b[i].pname, (mysqli_read_t)b[i].r_func, (mysqli_write_t)b[i].w_func TSRMLS_CC); \
i++; \
}\
}
#if WIN32|WINNT
#define SCLOSE(a) closesocket(a)
#else
#define SCLOSE(a) close(a)
#endif
#define MYSQLI_STORE_RESULT 0
#define MYSQLI_USE_RESULT 1
#ifdef MYSQLI_USE_MYSQLND
#ifdef MYSQLI_USE_MYSQLND
#ifdef MYSQLND_THREADED
#define MYSQLI_BG_STORE_RESULT 101
#endif
@ -326,12 +314,6 @@ PHP_MYSQLI_EXPORT(zend_object_value) mysqli_objects_new(zend_class_entry * TSRML
#define MYSQLI_NUM 2
#define MYSQLI_BOTH 3
/* for mysqli_bind_param */
#define MYSQLI_BIND_INT 1
#define MYSQLI_BIND_DOUBLE 2
#define MYSQLI_BIND_STRING 3
#define MYSQLI_BIND_SEND_DATA 4
/* fetch types */
#define FETCH_SIMPLE 1
#define FETCH_RESULT 2
@ -354,11 +336,6 @@ if ((MyG(report_mode) & MYSQLI_REPORT_ERROR) && mysql_stmt_errno(stmt)) { \
php_mysqli_report_error(mysql_stmt_sqlstate(stmt), mysql_stmt_errno(stmt), mysql_stmt_error(stmt) TSRMLS_CC); \
}
PHP_MYSQLI_API void mysqli_register_link(zval *return_value, void *link TSRMLS_DC);
PHP_MYSQLI_API void mysqli_register_stmt(zval *return_value, void *stmt TSRMLS_DC);
PHP_MYSQLI_API void mysqli_register_result(zval *return_value, void *result TSRMLS_DC);
PHP_MYSQLI_API 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);
@ -390,9 +367,6 @@ ZEND_BEGIN_MODULE_GLOBALS(mysqli)
#endif
ZEND_END_MODULE_GLOBALS(mysqli)
#define MYSQLI_PROPERTY(a) extern int a(mysqli_object *obj, zval **retval TSRMLS_DC)
MYSQLI_PROPERTY(my_prop_link_host);
#ifdef ZTS
#define MyG(v) TSRMG(mysqli_globals_id, zend_mysqli_globals *, v)
@ -512,10 +486,10 @@ PHP_FUNCTION(mysqli_thread_safe);
PHP_FUNCTION(mysqli_use_result);
PHP_FUNCTION(mysqli_warning_count);
ZEND_FUNCTION(mysqli_stmt_construct);
ZEND_FUNCTION(mysqli_result_construct);
ZEND_FUNCTION(mysqli_driver_construct);
ZEND_METHOD(mysqli_warning,__construct);
PHP_FUNCTION(mysqli_stmt_construct);
PHP_FUNCTION(mysqli_result_construct);
PHP_FUNCTION(mysqli_driver_construct);
PHP_METHOD(mysqli_warning,__construct);
#endif /* PHP_MYSQLI_STRUCTS.H */

20
ext/mysqli/tests/057.phpt

@ -62,6 +62,24 @@ require_once('skipifconnectfailure.inc');
bool(true)
bool(true)
object(mysqli_stmt)#%d (%d) {
["affected_rows"]=>
int(-1)
["insert_id"]=>
int(0)
["num_rows"]=>
int(0)
["param_count"]=>
int(0)
["field_count"]=>
int(1)
["errno"]=>
int(0)
["error"]=>
string(0) ""
["sqlstate"]=>
string(5) "00000"
["id"]=>
int(3)
}
bool(true)
bool(false)
@ -91,4 +109,4 @@ array(1) {
[0]=>
unicode(1) "1"
}
done!
done!

83
ext/mysqli/tests/bug34810.phpt

@ -16,7 +16,8 @@ class DbConnection {
var_dump($link);
$link = mysqli_init();
var_dump($link);
/* @ is to supress 'Property access is not allowed yet' */
@var_dump($link);
$mysql = new mysqli($host, $user, $passwd, $db, $port, $socket);
$mysql->query("DROP TABLE IF EXISTS test_warnings");
@ -33,10 +34,84 @@ $db->connect();
echo "Done\n";
?>
--EXPECTF--
object(mysqli)#%d (0) {
object(mysqli)#%d (%d) {
["affected_rows"]=>
int(0)
["client_info"]=>
string(%d) "%s"
["client_version"]=>
int(%d)
["connect_errno"]=>
int(0)
["connect_error"]=>
string(0) ""
["errno"]=>
int(0)
["error"]=>
string(0) ""
["field_count"]=>
int(0)
["host_info"]=>
string(42) "MySQL host info: Localhost via UNIX socket"
["info"]=>
NULL
["insert_id"]=>
int(0)
["server_info"]=>
string(%d) "%s"
["server_version"]=>
int(%d)
["sqlstate"]=>
string(5) "00000"
["protocol_version"]=>
int(10)
["thread_id"]=>
int(%d)
["warning_count"]=>
int(0)
}
object(mysqli)#%d (0) {
object(mysqli)#%d (%d) {
["affected_rows"]=>
NULL
["client_info"]=>
string(%d) "%s"
["client_version"]=>
int(%d)
["connect_errno"]=>
int(0)
["connect_error"]=>
string(0) ""
["errno"]=>
int(0)
["error"]=>
string(0) ""
["field_count"]=>
NULL
["host_info"]=>
NULL
["info"]=>
NULL
["insert_id"]=>
NULL
["server_info"]=>
NULL
["server_version"]=>
NULL
["sqlstate"]=>
NULL
["protocol_version"]=>
NULL
["thread_id"]=>
NULL
["warning_count"]=>
NULL
}
object(mysqli_warning)#%d (0) {
object(mysqli_warning)#%d (%d) {
["message"]=>
string(25) "Column 'a' cannot be null"
["sqlstate"]=>
string(5) "HY000"
["errno"]=>
int(1048)
}
Done

18
ext/mysqli/tests/mysqli_class_mysqli_driver_interface.phpt

@ -46,13 +46,13 @@ require_once('skipifconnectfailure.inc');
printf("ok\n");
printf("\nClass variables:\n");
$variables = get_class_vars(get_class($driver));
$variables = array_keys(get_class_vars(get_class($driver)));
sort($variables);
foreach ($variables as $k => $var)
printf("%s\n", $var);
printf("\nObject variables:\n");
$variables = get_object_vars($driver);
$variables = array_keys(get_object_vars($driver));
foreach ($variables as $k => $var)
printf("%s\n", $var);
@ -99,8 +99,20 @@ Methods:
ok
Class variables:
client_info
client_version
driver_version
embedded
reconnect
report_mode
Object variables:
client_info
client_version
driver_version
embedded
reconnect
report_mode
Magic, magic properties:
driver->client_info = '%s'
@ -112,4 +124,4 @@ driver->reconnect = ''
Access to undefined properties:
driver->unknown = ''
done!
done!

56
ext/mysqli/tests/mysqli_class_mysqli_driver_reflection.phpt

@ -37,4 +37,58 @@ isIteratable: no
Modifiers: '%d'
Parent Class: ''
Extension: 'mysqli'
done!
Inspecting property 'client_info'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'client_version'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'driver_version'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'embedded'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'reconnect'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'report_mode'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Default property 'client_info'
Default property 'client_version'
Default property 'driver_version'
Default property 'embedded'
Default property 'reconnect'
Default property 'report_mode'
done!

72
ext/mysqli/tests/mysqli_class_mysqli_interface.phpt

@ -92,13 +92,13 @@ require_once('skipifconnectfailure.inc');
printf("ok\n");
printf("\nClass variables:\n");
$variables = get_class_vars(get_class($mysqli));
$variables = array_keys(get_class_vars(get_class($mysqli)));
sort($variables);
foreach ($variables as $k => $var)
printf("%s\n", $var);
printf("\nObject variables:\n");
$variables = get_object_vars($mysqli);
$variables = array_keys(get_object_vars($mysqli));
foreach ($variables as $k => $var)
printf("%s\n", $var);
@ -213,8 +213,42 @@ Methods:
ok
Class variables:
affected_rows
client_info
client_version
connect_errno
connect_error
errno
error
field_count
host_info
info
insert_id
protocol_version
server_info
server_version
sqlstate
thread_id
warning_count
Object variables:
affected_rows
client_info
client_version
connect_errno
connect_error
errno
error
field_count
host_info
info
insert_id
server_info
server_version
sqlstate
protocol_version
thread_id
warning_count
Magic, magic properties:
mysqli->affected_rows = '%s'/integer ('%s'/integer)
@ -250,8 +284,42 @@ Methods:
ok
Class variables:
affected_rows
client_info
client_version
connect_errno
connect_error
errno
error
field_count
host_info
info
insert_id
protocol_version
server_info
server_version
sqlstate
thread_id
warning_count
Object variables:
affected_rows
client_info
client_version
connect_errno
connect_error
errno
error
field_count
host_info
info
insert_id
server_info
server_version
sqlstate
protocol_version
thread_id
warning_count
Magic, magic properties:
mysqli->affected_rows = '%s'/integer ('%s'/integer)

156
ext/mysqli/tests/mysqli_class_mysqli_reflection.phpt

@ -24,7 +24,7 @@ if ($MYSQLND_VERSION < 576)
require_once('reflection_tools.inc');
$class = new ReflectionClass('mysqli');
inspectClass($class);
print "done!";
print "done!\n";
?>
--EXPECTF--
Inspecting class 'mysqli'
@ -646,4 +646,158 @@ returnsReference: no
Modifiers: 256
Number of Parameters: 0
Number of Required Parameters: 0
Inspecting property 'affected_rows'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'client_info'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'client_version'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'connect_errno'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'connect_error'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'errno'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'error'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'field_count'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'host_info'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'info'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'insert_id'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'protocol_version'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'server_info'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'server_version'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'sqlstate'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'thread_id'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'warning_count'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Default property 'affected_rows'
Default property 'client_info'
Default property 'client_version'
Default property 'connect_errno'
Default property 'connect_error'
Default property 'errno'
Default property 'error'
Default property 'field_count'
Default property 'host_info'
Default property 'info'
Default property 'insert_id'
Default property 'protocol_version'
Default property 'server_info'
Default property 'server_version'
Default property 'sqlstate'
Default property 'thread_id'
Default property 'warning_count'
done!

26
ext/mysqli/tests/mysqli_class_mysqli_result_interface.phpt

@ -67,13 +67,13 @@ require_once('skipifconnectfailure.inc');
printf("\nClass variables:\n");
$variables = get_class_vars(get_class($mysqli_result));
$variables = array_keys(get_class_vars(get_class($mysqli_result)));
sort($variables);
foreach ($variables as $k => $var)
printf("%s\n", $var);
printf("\nObject variables:\n");
$variables = get_object_vars($mysqli_result);
$variables = array_keys(get_object_vars($mysqli_result));
foreach ($variables as $k => $var)
printf("%s\n", $var);
@ -162,8 +162,18 @@ Methods:
ok
Class variables:
current_field
field_count
lengths
num_rows
type
Object variables:
current_field
field_count
lengths
num_rows
type
Magic, magic properties:
mysqli_result->current_field = '0'/integer ('0'/integer)
@ -189,8 +199,18 @@ Methods:
ok
Class variables:
current_field
field_count
lengths
num_rows
type
Object variables:
current_field
field_count
lengths
num_rows
type
Magic, magic properties:
mysqli_result->current_field = '0'/integer ('0'/integer)
@ -207,4 +227,4 @@ Constructor:
Warning: mysqli_result::mysqli_result() expects parameter 2 to be long, Unicode string given in %s on line %d
Warning: mysqli_result::mysqli_result() expects parameter 1 to be mysqli, Unicode string given in %s on line %d
done!
done!

47
ext/mysqli/tests/mysqli_class_mysqli_result_reflection.phpt

@ -279,4 +279,49 @@ returnsReference: no
Modifiers: %d
Number of Parameters: 0
Number of Required Parameters: 0
done!
Inspecting property 'current_field'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'field_count'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'lengths'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'num_rows'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'type'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Default property 'current_field'
Default property 'field_count'
Default property 'lengths'
Default property 'num_rows'
Default property 'type'
done!

42
ext/mysqli/tests/mysqli_class_mysqli_stmt_interface.phpt

@ -67,13 +67,13 @@ Interface of the class mysqli_stmt
printf("ok\n");
printf("\nClass variables:\n");
$variables = get_class_vars(get_class($stmt));
$variables = array_keys(get_class_vars(get_class($stmt)));
sort($variables);
foreach ($variables as $k => $var)
printf("%s\n", $var);
printf("\nObject variables:\n");
$variables = get_object_vars($stmt);
$variables = array_keys(get_object_vars($stmt));
foreach ($variables as $k => $var)
printf("%s\n", $var);
@ -138,8 +138,26 @@ Methods:
ok
Class variables:
affected_rows
errno
error
field_count
id
insert_id
num_rows
param_count
sqlstate
Object variables:
affected_rows
insert_id
num_rows
param_count
field_count
errno
error
sqlstate
id
Magic, magic properties:
@ -176,8 +194,26 @@ Methods:
ok
Class variables:
affected_rows
errno
error
field_count
id
insert_id
num_rows
param_count
sqlstate
Object variables:
affected_rows
insert_id
num_rows
param_count
field_count
errno
error
sqlstate
id
Magic, magic properties:
@ -205,4 +241,4 @@ stmt->unknown = '13'
Prepare using the constructor:
Warning: mysqli_stmt::mysqli_stmt() expects parameter 2 to be binary string, object given in %s on line %d
done!
done!

31
ext/mysqli/tests/mysqli_class_mysqli_warning_reflection.phpt

@ -24,7 +24,7 @@ if ($MYSQLND_VERSION < 576)
require_once('reflection_tools.inc');
$class = new ReflectionClass('mysqli_warning');
inspectClass($class);
print "done!";
print "done!\n";
?>
--EXPECTF--
Inspecting class 'mysqli_warning'
@ -86,4 +86,31 @@ returnsReference: no
Modifiers: %d
Number of Parameters: 0
Number of Required Parameters: 0
done!
Inspecting property 'errno'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'message'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Inspecting property 'sqlstate'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 256
Default property 'errno'
Default property 'message'
Default property 'sqlstate'
done!

27
ext/mysqli/tests/mysqli_connect_oo.phpt

@ -50,17 +50,32 @@ new mysqli()
ini_set('mysqli.default_host', $host);
if (!is_object($mysqli = new mysqli()) || (0 !== mysqli_connect_errno())) {
printf("[008] Usage of mysqli.default_host failed\n") ;
printf("[012] Failed to create mysqli object\n");
} else {
$mysqli->close();
// There shall be NO connection! Using new mysqli(void) shall not use defaults for a connection!
// We had long discussions on this and found that the ext/mysqli API as
// such is broken. As we can't fix it, we document how it has behaved from
// the first day on. And that's: no connection.
if (NULL !== ($tmp = @$mysqli->query('SELECT 1'))) {
printf("[013] There shall be no connection!\n");
$mysqli->close();
}
}
if ($IS_MYSQLND) {
ini_set('mysqli.default_host', 'p:' . $host);
if (!is_object($mysqli = new mysqli()) || (0 !== mysqli_connect_errno())) {
printf("[008b] Usage of mysqli.default_host failed\n") ;
if (!is_object($mysqli = new mysqli())) {
// Due to an API flaw this shall not connect
printf("[010] Failed to create mysqli object\n");
} else {
$mysqli->close();
// There shall be NO connection! Using new mysqli(void) shall not use defaults for a connection!
// We had long discussions on this and found that the ext/mysqli API as
// such is broken. As we can't fix it, we document how it has behaved from
// the first day on. And that's: no connection.
if (NULL !== ($tmp = @$mysqli->query('SELECT 1'))) {
printf("[011] There shall be no connection!\n");
$mysqli->close();
}
}
}
@ -130,8 +145,6 @@ new mysqli()
?>
--EXPECTF--
Warning: mysqli::mysqli(): (%d/%d): Access denied for user '%sunknown%s'@'%s' (using password: %s) in %s on line %d
Warning: mysqli::close(): Couldn't fetch mysqli in %s on line %d
... and now Exceptions
Access denied for user '%s'@'%s' (using password: %s)
done!

4
ext/mysqli/tests/mysqli_constants.phpt

@ -93,13 +93,13 @@ require_once('skipifconnectfailure.inc');
$expected_constants['MYSQLI_OPT_NET_CMD_BUFFER_SIZE'] = true;
$expected_constants['MYSQLI_OPT_NET_READ_BUFFER_SIZE'] = true;
$expected_constants['MYSQLI_DEBUG_TRACE_ENABLED'] = true;
} else {
$version = mysqli_get_client_version();
}
if (($version > 51122 && $version < 60000) || ($version > 60003) || $IS_MYSQLND) {
$expected_constants['MYSQLI_ON_UPDATE_NOW_FLAG'] = true;
$expected_constants['MYSQLI_ON_UPDATE_NOW_FLAG'] = true;
}
if ($version > 50002) {

6
ext/mysqli/tests/mysqli_debug.phpt

@ -8,6 +8,12 @@ require_once('skipifconnectfailure.inc');
if (!function_exists('mysqli_debug'))
die("skip: mysqli_debug() not available");
if (!defined('MYSQLI_DEGBUG_TRACE_ENABLED'))
die("skip: can't say for sure if mysqli_debug works");
if (defined('MYSQLI_DEBUG_TRACE_ENABLED') && !MYSQLI_DEBUG_TRACE_ENABLED)
die("skip: debug functionality not enabled");
?>
--FILE--
<?php

6
ext/mysqli/tests/mysqli_debug_append.phpt

@ -8,6 +8,12 @@ require_once('skipifconnectfailure.inc');
if (!function_exists('mysqli_debug'))
die("skip: mysqli_debug() not available");
if (!defined('MYSQLI_DEGBUG_TRACE_ENABLED'))
die("skip: can't say for sure if mysqli_debug works");
if (defined('MYSQLI_DEBUG_TRACE_ENABLED') && !MYSQLI_DEBUG_TRACE_ENABLED)
die("skip: debug functionality not enabled");
?>
--FILE--
<?php

6
ext/mysqli/tests/mysqli_debug_control_string.phpt

@ -8,6 +8,12 @@ require_once('skipifconnectfailure.inc');
if (!function_exists('mysqli_debug'))
die("skip: mysqli_debug() not available");
if (!defined('MYSQLI_DEGBUG_TRACE_ENABLED'))
die("skip: can't say for sure if mysqli_debug works");
if (defined('MYSQLI_DEBUG_TRACE_ENABLED') && !MYSQLI_DEBUG_TRACE_ENABLED)
die("skip: debug functionality not enabled");
?>
--FILE--
<?php

6
ext/mysqli/tests/mysqli_debug_ini.phpt

@ -8,6 +8,12 @@ require_once('skipifemb.inc');
if (!function_exists('mysqli_debug'))
die("skip mysqli_debug() not available");
if (!defined('MYSQLI_DEGBUG_TRACE_ENABLED'))
die("skip: can't say for sure if mysqli_debug works");
if (defined('MYSQLI_DEBUG_TRACE_ENABLED') && !MYSQLI_DEBUG_TRACE_ENABLED)
die("skip: debug functionality not enabled");
require_once('connect.inc');
if (!$IS_MYSQLND || ($MYSQLND_VERSION < 940))
die("skip needs mysqlnd version/revision 940+");

6
ext/mysqli/tests/mysqli_debug_mysqlnd_control_string.phpt

@ -8,6 +8,12 @@ require_once('skipifconnectfailure.inc');
if (!function_exists('mysqli_debug'))
die("skip: mysqli_debug() not available");
if (!defined('MYSQLI_DEGBUG_TRACE_ENABLED'))
die("skip: can't say for sure if mysqli_debug works");
if (defined('MYSQLI_DEBUG_TRACE_ENABLED') && !MYSQLI_DEBUG_TRACE_ENABLED)
die("skip: debug functionality not enabled");
?>
--FILE--
<?php

6
ext/mysqli/tests/mysqli_debug_mysqlnd_only.phpt

@ -10,6 +10,12 @@ require_once('connect.inc');
if (!function_exists('mysqli_debug'))
die("skip mysqli_debug() not available");
if (!defined('MYSQLI_DEGBUG_TRACE_ENABLED'))
die("skip: can't say for sure if mysqli_debug works");
if (defined('MYSQLI_DEBUG_TRACE_ENABLED') && !MYSQLI_DEBUG_TRACE_ENABLED)
die("skip: debug functionality not enabled");
if (!$IS_MYSQLND)
die("skip mysqlnd only test");
?>

38
ext/mysqli/tests/mysqli_kill.phpt

@ -68,7 +68,41 @@ require_once('skipifconnectfailure.inc');
Warning: mysqli_kill(): processid should have positive value in %s on line %d
string(%d) "%s"
bool(false)
object(mysqli)#%d (0) {
object(mysqli)#%d (%d) {
["affected_rows"]=>
int(-1)
["client_info"]=>
string(%d) "%s"
["client_version"]=>
int(%d)
["connect_errno"]=>
int(0)
["connect_error"]=>
string(0) ""
["errno"]=>
int(2006)
["error"]=>
string(26) "MySQL server has gone away"
["field_count"]=>
int(0)
["host_info"]=>
string(42) "MySQL host info: Localhost via UNIX socket"
["info"]=>
string(38) "Records: 6 Duplicates: 0 Warnings: 0"
["insert_id"]=>
int(0)
["server_info"]=>
string(%d) "%s"
["server_version"]=>
int(%d)
["sqlstate"]=>
string(5) "HY000"
["protocol_version"]=>
int(10)
["thread_id"]=>
int(%d)
["warning_count"]=>
int(0)
}
Warning: mysqli_kill(): processid should have positive value in %s on line %d
@ -93,4 +127,4 @@ array(1) {
}
Warning: mysqli_kill(): processid should have positive value in %s on line %d
done!
done!

23
ext/mysqli/tests/mysqli_options.phpt

@ -1,14 +1,33 @@
--TEST--
mysqli_options()
--SKIPIF--
<?php
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');
require_once('skipifemb.inc');
require_once('skipifconnectfailure.inc');
?>
--FILE--
<?php
include "connect.inc";
/*
TODO: ext/mysqli might lack support for those options which are available
with the libmysql C call mysql_options(). Not sure which of them make
sense to have in PHP and not even sure which of them might be available
already through other measures.
MYSQL_OPT_COMPRESS (argument: not used) --> Andrey/Ulf: bug, should be added
? MYSQL_OPT_NAMED_PIPE (argument: not used) ?
MYSQL_OPT_READ_TIMEOUT (argument type: unsigned int *) --> Andrey/Ulf: bug, should be added
MYSQL_OPT_RECONNECT (argument type: my_bool *) --> Andrey/Ulf: might be security risk to have
MYSQL_OPT_SSL_VERIFY_SERVER_CERT (argument type: my_bool *) --> Andrey/Ulf: might be security risk to have
MYSQL_OPT_WRITE_TIMEOUT (argument type: unsigned int *) --> Andrey/Ulf: bug, should be added
MYSQL_REPORT_DATA_TRUNCATION (argument type: my_bool *) --> Andrey: bug, although truncation might only happen with libmysql not with mysqlnd
MYSQL_SECURE_AUTH (argument type: my_bool *) --> Ulf: let's say deprecated, no bug
? MYSQL_SET_CHARSET_DIR (argument type: char *) ?
MYSQL_SHARED_MEMORY_BASE_NAME (argument type: char *)
*/
$valid_options = array( MYSQLI_READ_DEFAULT_GROUP, MYSQLI_READ_DEFAULT_FILE,
MYSQLI_OPT_CONNECT_TIMEOUT, MYSQLI_OPT_LOCAL_INFILE,
MYSQLI_INIT_COMMAND, MYSQLI_READ_DEFAULT_GROUP,

36
ext/mysqli/tests/mysqli_real_connect.phpt

@ -163,7 +163,7 @@ require_once('skipifconnectfailure.inc');
}
}
var_dump($link);
@var_dump($link);
if (NULL === ($tmp = mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket)))
printf("[026] Expecting not NULL, got %s/%s\n", gettype($tmp), $tmp);
@ -173,5 +173,39 @@ require_once('skipifconnectfailure.inc');
--EXPECTF--
Warning: mysqli_real_connect(): (%d/%d): Access denied for user '%s'@'%s' (using password: YES) in %s on line %d
object(mysqli)#%d (%d) {
["affected_rows"]=>
NULL
["client_info"]=>
string(%d) "%s"
["client_version"]=>
int(%d)
["connect_errno"]=>
int(%d)
["connect_error"]=>
string(%d) "%s"
["errno"]=>
int(%d)
["error"]=>
string(%d) "%s"
["field_count"]=>
NULL
["host_info"]=>
NULL
["info"]=>
NULL
["insert_id"]=>
NULL
["server_info"]=>
NULL
["server_version"]=>
NULL
["sqlstate"]=>
NULL
["protocol_version"]=>
NULL
["thread_id"]=>
NULL
["warning_count"]=>
NULL
}
done!

4
ext/mysqli/tests/mysqli_result_references.phpt

@ -59,7 +59,7 @@ require_once('skipifconnectfailure.inc');
$references[$idx++] = &$res;
mysqli_free_result($res);
debug_zval_dump($references);
@debug_zval_dump($references);
if (!(mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 1")) ||
!($res = mysqli_use_result($link)))
@ -199,4 +199,4 @@ array(1) refcount(2){
unicode(1) "a" { 0061 } refcount(1)
}
}
done!
done!

2
ext/mysqli/tests/mysqli_stmt_attr_get.phpt

@ -63,4 +63,4 @@ require_once('skipifconnectfailure.inc');
print "done!";
?>
--EXPECTF--
done!
done!

6
ext/mysqlnd/mysqlnd_priv.h

@ -148,9 +148,9 @@
#define SET_CLIENT_ERROR(error_info, a, b, c) \
{ \
error_info.error_no = a; \
strlcpy(error_info.sqlstate, b, sizeof(error_info.sqlstate)); \
strlcpy(error_info.error, c, sizeof(error_info.error)); \
error_info.error_no = (a); \
strlcpy(error_info.sqlstate, (b), sizeof(error_info.sqlstate)); \
strlcpy(error_info.error, (c), sizeof(error_info.error)); \
}
#define SET_STMT_ERROR(stmt, a, b, c) SET_CLIENT_ERROR(stmt->error_info, a, b, c)

Loading…
Cancel
Save