summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/mysqli/config.m42
-rw-r--r--ext/mysqli/mysqli.c58
-rw-r--r--ext/mysqli/mysqli_api.c46
-rw-r--r--ext/mysqli/mysqli_driver.c153
-rw-r--r--ext/mysqli/mysqli_embedded.c124
-rw-r--r--ext/mysqli/mysqli_exception.c74
-rw-r--r--ext/mysqli/mysqli_fe.c11
-rw-r--r--ext/mysqli/mysqli_nonapi.c72
-rw-r--r--ext/mysqli/mysqli_prop.c1
-rw-r--r--ext/mysqli/mysqli_report.c4
-rw-r--r--ext/mysqli/mysqli_warning.c172
-rw-r--r--ext/mysqli/php_mysqli.h60
-rw-r--r--ext/mysqli/tests/001.phpt3
-rw-r--r--ext/mysqli/tests/014.phpt2
-rw-r--r--ext/mysqli/tests/017.phpt1
-rw-r--r--ext/mysqli/tests/033.phpt1
-rw-r--r--ext/mysqli/tests/034.phpt1
-rw-r--r--ext/mysqli/tests/041.phpt2
-rw-r--r--ext/mysqli/tests/045.phpt1
-rw-r--r--ext/mysqli/tests/047.phpt4
-rw-r--r--ext/mysqli/tests/049.phpt1
-rw-r--r--ext/mysqli/tests/061.phpt1
-rw-r--r--ext/mysqli/tests/connect.inc22
-rw-r--r--ext/mysqli/tests/skipif.inc5
-rw-r--r--ext/mysqli/tests/skipifemb.inc5
25 files changed, 681 insertions, 145 deletions
diff --git a/ext/mysqli/config.m4 b/ext/mysqli/config.m4
index 2cbd5a6680..74b6f52e7f 100644
--- a/ext/mysqli/config.m4
+++ b/ext/mysqli/config.m4
@@ -54,6 +54,6 @@ if test "$PHP_MYSQLI" != "no"; then
$MYSQLI_LIBLINE
])
- PHP_NEW_EXTENSION(mysqli, mysqli.c mysqli_api.c mysqli_prop.c mysqli_nonapi.c mysqli_fe.c mysqli_report.c mysqli_repl.c, $ext_shared)
+ PHP_NEW_EXTENSION(mysqli, mysqli.c mysqli_api.c mysqli_prop.c mysqli_nonapi.c mysqli_fe.c mysqli_report.c mysqli_repl.c mysqli_driver.c mysqli_warning.c mysqli_exception.c mysqli_embedded.c, $ext_shared)
PHP_SUBST(MYSQLI_SHARED_LIBADD)
fi
diff --git a/ext/mysqli/mysqli.c b/ext/mysqli/mysqli.c
index 5f41bde47d..062b23bad8 100644
--- a/ext/mysqli/mysqli.c
+++ b/ext/mysqli/mysqli.c
@@ -37,9 +37,12 @@
ZEND_DECLARE_MODULE_GLOBALS(mysqli)
static zend_object_handlers mysqli_object_handlers;
static HashTable classes;
+static HashTable mysqli_driver_properties;
static HashTable mysqli_link_properties;
static HashTable mysqli_result_properties;
static HashTable mysqli_stmt_properties;
+static HashTable mysqli_warning_properties;
+
extern void php_mysqli_connect(INTERNAL_FUNCTION_PARAMETERS);
typedef int (*mysqli_read_t)(mysqli_object *obj, zval **retval TSRMLS_DC);
@@ -142,6 +145,10 @@ static void mysqli_objects_free_storage(zend_object *object TSRMLS_DC)
if (my_res && my_res->ptr) {
mysql_free_result(my_res->ptr);
}
+ } else if (intern->zo.ce == mysqli_warning_class_entry) { /* warning object */
+ if (my_res && my_res->ptr) {
+ php_clear_warnings((MYSQLI_WARNING *)my_res->ptr);
+ }
}
my_efree(my_res);
efree(object);
@@ -282,7 +289,8 @@ static union _zend_function *php_mysqli_constructor_get(zval *object TSRMLS_DC)
mysqli_object *obj = (mysqli_object *)zend_objects_get_address(object TSRMLS_CC);
if (obj->zo.ce != mysqli_link_class_entry && obj->zo.ce != mysqli_stmt_class_entry &&
- obj->zo.ce != mysqli_result_class_entry) {
+ obj->zo.ce != mysqli_result_class_entry && obj->zo.ce != mysqli_driver_class_entry &&
+ obj->zo.ce != mysqli_warning_class_entry) {
return obj->zo.ce->constructor;
} else {
static zend_internal_function f;
@@ -300,6 +308,10 @@ static union _zend_function *php_mysqli_constructor_get(zval *object TSRMLS_DC)
f.handler = ZEND_FN(mysqli_stmt_construct);
} else if (obj->zo.ce == mysqli_result_class_entry) {
f.handler = ZEND_FN(mysqli_result_construct);
+ } else if (obj->zo.ce == mysqli_driver_class_entry) {
+ f.handler = ZEND_FN(mysqli_driver_construct);
+ } else if (obj->zo.ce == mysqli_warning_class_entry) {
+ f.handler = ZEND_FN(mysqli_driver_construct);
}
return (union _zend_function*)&f;
@@ -397,6 +409,11 @@ static void php_mysqli_init_globals(zend_mysqli_globals *mysqli_globals)
mysqli_globals->report_mode = 0;
mysqli_globals->report_ht = 0;
mysqli_globals->multi_query = 0;
+#ifdef HAVE_EMBEDDED_MYSQLI
+ mysqli_globals->embedded = 1;
+#else
+ mysqli_globals->embedded = 0;
+#endif
}
/* }}} */
@@ -404,9 +421,8 @@ static void php_mysqli_init_globals(zend_mysqli_globals *mysqli_globals)
*/
PHP_MINIT_FUNCTION(mysqli)
{
- zend_class_entry *ce;
+ zend_class_entry *ce,cex;
zend_object_handlers *std_hnd = zend_get_std_object_handlers();
-
ZEND_INIT_MODULE_GLOBALS(mysqli, php_mysqli_init_globals, NULL);
REGISTER_INI_ENTRIES();
@@ -420,13 +436,37 @@ PHP_MINIT_FUNCTION(mysqli)
zend_hash_init(&classes, 0, NULL, NULL, 1);
- REGISTER_MYSQLI_CLASS_ENTRY("mysqli", mysqli_link_class_entry, mysqli_link_methods);
+ INIT_CLASS_ENTRY(cex, "mysqli_sql_exception", mysqli_exception_methods);
+#ifdef HAVE_SPL
+ mysqli_exception_class_entry = zend_register_internal_class_ex(&cex, spl_ce_RuntimeException, NULL TSRMLS_CC);
+#else
+ mysqli_exception_class_entry = zend_register_internal_class_ex(&cex, zend_exception_get_default(), NULL TSRMLS_CC);
+#endif
+ mysqli_exception_class_entry->ce_flags |= ZEND_ACC_FINAL;
+ zend_declare_property_long(mysqli_exception_class_entry, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED TSRMLS_CC);
+ zend_declare_property_string(mysqli_exception_class_entry, "sqlstate", sizeof("sqlstate")-1, "00000", ZEND_ACC_PROTECTED TSRMLS_CC);
+ REGISTER_MYSQLI_CLASS_ENTRY("mysqli_driver", mysqli_driver_class_entry, mysqli_driver_methods);
+ ce = mysqli_driver_class_entry;
+ zend_hash_init(&mysqli_driver_properties, 0, NULL, NULL, 1);
+ MYSQLI_ADD_PROPERTIES(&mysqli_driver_properties, mysqli_driver_property_entries);
+ zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_driver_properties, sizeof(mysqli_driver_properties), NULL);
+ ce->ce_flags |= ZEND_ACC_FINAL;
+
+ REGISTER_MYSQLI_CLASS_ENTRY("mysqli", mysqli_link_class_entry, mysqli_link_methods);
ce = mysqli_link_class_entry;
zend_hash_init(&mysqli_link_properties, 0, NULL, NULL, 1);
MYSQLI_ADD_PROPERTIES(&mysqli_link_properties, mysqli_link_property_entries);
zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_link_properties, sizeof(mysqli_link_properties), NULL);
+ REGISTER_MYSQLI_CLASS_ENTRY("mysqli_warning", mysqli_warning_class_entry, mysqli_warning_methods);
+ ce = mysqli_warning_class_entry;
+ ce->ce_flags |= ZEND_ACC_FINAL;
+ zend_hash_init(&mysqli_warning_properties, 0, NULL, NULL, 1);
+ MYSQLI_ADD_PROPERTIES(&mysqli_warning_properties, mysqli_warning_property_entries);
+ zend_hash_add(&classes, ce->name, ce->name_length+1, &mysqli_warning_properties, sizeof(mysqli_warning_properties), NULL);
+ ce->ce_flags |= ZEND_ACC_FINAL;
+
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);
@@ -538,9 +578,11 @@ PHP_MINIT_FUNCTION(mysqli)
*/
PHP_MSHUTDOWN_FUNCTION(mysqli)
{
- zend_hash_destroy(&mysqli_link_properties);
+// zend_hash_destroy(&mysqli_driver_properties);
zend_hash_destroy(&mysqli_result_properties);
zend_hash_destroy(&mysqli_stmt_properties);
+ zend_hash_destroy(&mysqli_warning_properties);
+ zend_hash_destroy(&mysqli_link_properties);
zend_hash_destroy(&classes);
UNREGISTER_INI_ENTRIES();
@@ -708,6 +750,7 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
int class_name_len;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|sz", &mysql_result, mysqli_result_class_entry, &class_name, &class_name_len, &ctor_params) == FAILURE) {
+ // php_std_error_handling();
return;
}
if (ZEND_NUM_ARGS() < (getThis() ? 1 : 2)) {
@@ -723,17 +766,18 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
} else {
if (override_flags) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
+ //php_std_error_handling();
return;
}
fetchtype = override_flags;
} else {
fetchtype = MYSQLI_BOTH;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|l", &mysql_result, mysqli_result_class_entry, &fetchtype) == FAILURE) {
+ // php_std_error_handling();
return;
}
}
}
-
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result");
if (!(row = mysql_fetch_row(result))) {
@@ -930,6 +974,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)
{
mysqli_local_infile *data;
@@ -1003,6 +1048,7 @@ int php_local_infile_read(void *ptr, char *buf, uint buf_len)
efree(fp);
return rc;
}
+/* }}} */
/* {{{ php_local_infile_error
*/
diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c
index 3c1be87314..e958434f31 100644
--- a/ext/mysqli/mysqli_api.c
+++ b/ext/mysqli/mysqli_api.c
@@ -149,7 +149,7 @@ PHP_FUNCTION(mysqli_stmt_bind_param)
break;
case 'b': /* Blob (send data) */
- bind[ofs].buffer_type = MYSQL_TYPE_VAR_STRING;
+ bind[ofs].buffer_type = MYSQL_TYPE_LONG_BLOB;
bind[ofs].is_null = 0;
bind[ofs].length = 0;
break;
@@ -182,7 +182,7 @@ PHP_FUNCTION(mysqli_stmt_bind_param)
stmt->param.var_cnt = num_vars;
stmt->param.vars = (zval **)safe_emalloc(num_vars, sizeof(zval), 0);
for (i = 0; i < num_vars; i++) {
- if (bind[i].buffer_type != MYSQLI_BIND_SEND_DATA) {
+ if (bind[i].buffer_type != MYSQL_TYPE_LONG_BLOB) {
ZVAL_ADDREF(*args[i+start]);
stmt->param.vars[i] = *args[i+start];
} else {
@@ -564,6 +564,7 @@ PHP_FUNCTION(mysqli_stmt_execute)
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
RETURN_FALSE;
}
+
if (MyG(report_mode) & MYSQLI_REPORT_INDEX) {
php_mysqli_report_index(stmt->query, stmt->stmt->mysql->server_status TSRMLS_CC);
}
@@ -837,7 +838,7 @@ PHP_FUNCTION(mysqli_field_seek)
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, &mysql_result, "mysqli_result");
if (fieldnr < 0 || fieldnr >= mysql_num_fields(result)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Field offset is invalid for resultset");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Function cannot be used with MYSQL_USE_RESULT");
RETURN_FALSE;
}
@@ -1305,12 +1306,10 @@ PHP_FUNCTION(mysqli_real_connect)
if (mysql_real_connect(mysql->mysql,hostname,username,passwd,dbname,port,socket,flags) == NULL) {
- MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
php_mysqli_set_error(mysql_errno(mysql->mysql), (char *) mysql_error(mysql->mysql) TSRMLS_CC);
+ php_mysqli_throw_sql_exception( mysql->mysql->net.sqlstate, mysql->mysql->net.last_errno TSRMLS_CC,
+ mysql->mysql->net.last_error);
- if (!(MyG(report_mode) & MYSQLI_REPORT_ERROR)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", mysql_error(mysql->mysql));
- }
RETURN_FALSE;
}
php_mysqli_set_error(mysql_errno(mysql->mysql), (char *)mysql_error(mysql->mysql) TSRMLS_CC);
@@ -1422,39 +1421,6 @@ PHP_FUNCTION(mysqli_stmt_send_long_data)
}
/* }}} */
-#ifdef HAVE_EMBEDDED_MYSQLI
-/* {{{ proto bool mysqli_server_init(void)
- initialize embedded server */
-PHP_FUNCTION(mysqli_server_init)
-{
- zval *server;
- zval *groups;
-
- if (MyG(embedded)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Embedded server already initialized.");
- RETURN_FALSE;
- }
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|aa", &server, &groups) == FAILURE) {
- return;
- }
-
- if (mysql_server_init(0, NULL, NULL)) {
- RETURN_FALSE;
- }
- MyG(embedded) = 1;
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto void mysqli_server_end(void)
-*/
-PHP_FUNCTION(mysqli_server_end)
-{
- mysql_server_end();
-}
-/* }}} */
-#endif
/* {{{ proto mixed mysqli_stmt_affected_rows(object stmt)
Return the number of rows affected in the last query for the given link */
diff --git a/ext/mysqli/mysqli_driver.c b/ext/mysqli/mysqli_driver.c
new file mode 100644
index 0000000000..b8c9ca9ed2
--- /dev/null
+++ b/ext/mysqli/mysqli_driver.c
@@ -0,0 +1,153 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2004 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.0 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_0.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Georg Richter <georg@php.net> |
+ +----------------------------------------------------------------------+
+
+*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <signal.h>
+
+#include "php.h"
+#include "php_ini.h"
+#include "ext/standard/info.h"
+#include "php_mysqli.h"
+#include "zend_exceptions.h"
+
+
+#define MAP_PROPERTY_MYG_BOOL_READ(name, value) \
+int name(mysqli_object *obj, zval **retval TSRMLS_DC) \
+{ \
+ ALLOC_ZVAL(*retval); \
+ ZVAL_BOOL(*retval, MyG(value)); \
+ return SUCCESS; \
+} \
+
+#define MAP_PROPERTY_MYG_BOOL_WRITE(name, value) \
+int name(mysqli_object *obj, zval *value TSRMLS_DC) \
+{ \
+ MyG(value) = Z_LVAL_P(value) > 0; \
+ return SUCCESS; \
+} \
+
+#define MAP_PROPERTY_MYG_LONG_READ(name, value) \
+int name(mysqli_object *obj, zval **retval TSRMLS_DC) \
+{ \
+ ALLOC_ZVAL(*retval); \
+ ZVAL_LONG(*retval, MyG(value)); \
+ return SUCCESS; \
+} \
+
+#define MAP_PROPERTY_MYG_LONG_WRITE(name, value) \
+int name(mysqli_object *obj, zval *value TSRMLS_DC) \
+{ \
+ MyG(value) = Z_LVAL_P(value); \
+ return SUCCESS; \
+} \
+
+#define MAP_PROPERTY_MYG_STRING_READ(name, value) \
+int name(mysqli_object *obj, zval **retval TSRMLS_DC) \
+{ \
+ ALLOC_ZVAL(*retval); \
+ ZVAL_STRING(*retval, MyG(value), 1); \
+ return SUCCESS; \
+} \
+
+#define MAP_PROPERTY_MYG_STRING_WRITE(name, value) \
+int name(mysqli_object *obj, zval *value TSRMLS_DC) \
+{ \
+ MyG(value) = Z_STRVAL_P(value); \
+ return SUCCESS; \
+} \
+
+/* {{{ property driver_report_write */
+int driver_report_write(mysqli_object *obj, zval *value TSRMLS_DC)
+{
+ MyG(report_mode) = Z_LVAL_P(value);
+ php_set_error_handling(MyG(report_mode) & MYSQLI_REPORT_STRICT ? EH_THROW : EH_NORMAL,
+ zend_exception_get_default() TSRMLS_CC);
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ property driver_embedded_read */
+int driver_embedded_read(mysqli_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+#ifdef HAVE_EMBEDDED_MYSQLI
+ ZVAL_BOOL(*retval, 1);
+#else
+ ZVAL_BOOL(*retval, 0);
+#endif
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ property driver_client_version_read */
+int driver_client_version_read(mysqli_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_LONG(*retval, MYSQL_VERSION_ID);
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ property driver_client_info_read */
+int driver_client_info_read(mysqli_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_STRING(*retval, MYSQL_SERVER_VERSION, 1);
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ property driver_driver_version_read */
+int driver_driver_version_read(mysqli_object *obj, zval **retval TSRMLS_DC)
+{
+ ALLOC_ZVAL(*retval);
+ ZVAL_LONG(*retval, MYSQLI_VERSION_ID);
+ return SUCCESS;
+}
+/* }}} */
+
+MAP_PROPERTY_MYG_BOOL_READ(driver_reconnect_read, reconnect);
+MAP_PROPERTY_MYG_BOOL_WRITE(driver_reconnect_write, reconnect);
+MAP_PROPERTY_MYG_LONG_READ(driver_report_read, report_mode);
+
+ZEND_FUNCTION(mysqli_driver_construct)
+{
+
+}
+
+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}
+};
+
+/* {{{ mysqli_driver_methods[]
+ */
+function_entry mysqli_driver_methods[] = {
+ PHP_FALIAS(embedded_server_start, mysqli_embedded_server_start, NULL)
+ PHP_FALIAS(embedded_server_end, mysqli_embedded_server_end, NULL)
+ {NULL, NULL, NULL}
+};
+/* }}} */
diff --git a/ext/mysqli/mysqli_embedded.c b/ext/mysqli/mysqli_embedded.c
new file mode 100644
index 0000000000..9990bd9b5f
--- /dev/null
+++ b/ext/mysqli/mysqli_embedded.c
@@ -0,0 +1,124 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2004 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.0 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_0.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Georg Richter <georg@php.net> |
+ +----------------------------------------------------------------------+
+
+*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <signal.h>
+
+#include "php.h"
+#include "php_ini.h"
+#include "ext/standard/info.h"
+#include "php_mysqli.h"
+
+/* {{{ proto bool mysqli_embedded_server_start(bool start, array arguments, array groups)
+ initialize and start embedded server */
+PHP_FUNCTION(mysqli_embedded_server_start)
+{
+ int argc = 0;
+ char **arguments;
+ char **groups;
+ zval **args, **grps, **start;
+ HashPosition pos;
+ int index, rc;
+
+ if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &start, &args, &grps) == FAILURE) {
+ ZEND_WRONG_PARAM_COUNT();
+ }
+
+ convert_to_long_ex(start);
+ convert_to_array_ex(args);
+ convert_to_array_ex(grps);
+
+ if (!Z_LVAL_PP(start)) {
+ mysql_server_init(-1,NULL, NULL);
+ RETURN_TRUE;
+ }
+
+ if (MyG(embedded)) {
+ /* get arguments */
+ if ((argc = zend_hash_num_elements(HASH_OF(*args)))) {
+ arguments = safe_emalloc(sizeof(char *), argc + 1, 0);
+ arguments[0] = NULL;
+
+ zend_hash_internal_pointer_reset_ex(HASH_OF(*args), &pos);
+
+ for (index = 0;; zend_hash_move_forward_ex(HASH_OF(*args), &pos)) {
+ zval **item;
+
+ if (zend_hash_get_current_data_ex(HASH_OF(*args), (void **) &item, &pos) == FAILURE) {
+ break;
+ }
+
+ convert_to_string_ex(item);
+
+ arguments[++index] = Z_STRVAL_PP(item);
+ }
+ argc++;
+ }
+
+ /* get groups */
+ if ((zend_hash_num_elements(HASH_OF(*grps)))) {
+ groups = safe_emalloc(sizeof(char *), zend_hash_num_elements(HASH_OF(*grps)) + 1, 0);
+ arguments[0] = NULL;
+
+ zend_hash_internal_pointer_reset_ex(HASH_OF(*args), &pos);
+
+ for (index = 0;; zend_hash_move_forward_ex(HASH_OF(*args), &pos)) {
+ zval ** item;
+
+ if (zend_hash_get_current_data_ex(HASH_OF(*args), (void **) &item, &pos) == FAILURE) {
+ break;
+ }
+
+ convert_to_string_ex(item);
+
+ groups[++index] = Z_STRVAL_PP(item);
+ }
+ groups[index] = NULL;
+ } else {
+ groups = safe_emalloc(sizeof(char *), 1, 0);
+ groups[0] = NULL;
+ }
+
+ rc = mysql_server_init(argc, arguments, NULL);
+
+ if (argc) {
+ efree(arguments);
+ }
+ efree(groups);
+
+ if (rc) {
+ RETURN_FALSE;
+ }
+ RETURN_TRUE;
+ }
+
+ php_error_docref(NULL TSRMLS_CC, E_ERROR,
+ "Can't start embedded server. PHP wasn't configured with mysql embedded server support");
+}
+/* }}} */
+
+/* {{{ proto void mysqli_embedded_server_end(void)
+*/
+PHP_FUNCTION(mysqli_embedded_server_end)
+{
+ mysql_server_end();
+}
+/* }}} */
diff --git a/ext/mysqli/mysqli_exception.c b/ext/mysqli/mysqli_exception.c
new file mode 100644
index 0000000000..3d1732356b
--- /dev/null
+++ b/ext/mysqli/mysqli_exception.c
@@ -0,0 +1,74 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2004 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.0 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_0.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Georg Richter <georg@php.net> |
+ +----------------------------------------------------------------------+
+
+*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <signal.h>
+
+#include "php.h"
+#include "php_ini.h"
+#include "ext/standard/info.h"
+#include "php_mysqli.h"
+#include "zend_exceptions.h"
+
+/* {{{ mysqli_exception_methods[]
+ */
+function_entry mysqli_exception_methods[] = {
+ {NULL, NULL, NULL}
+};
+/* }}} */
+
+void php_mysqli_throw_sql_exception(char *sqlstate, int errorno TSRMLS_DC, char *format, ...)
+{
+ zval *sql_ex;
+ va_list arg;
+ char *message;
+
+ va_start(arg, format);
+ zend_vspprintf(&message, 0, format, arg);
+ va_end(arg);;
+
+ if (!(MyG(report_mode) & MYSQLI_REPORT_STRICT)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "(%s/%d): %s", sqlstate, errorno, message);
+ return;
+ }
+
+ MAKE_STD_ZVAL(sql_ex);
+ object_init_ex(sql_ex, mysqli_exception_class_entry);
+
+ if (message) {
+ zend_update_property_string(mysqli_exception_class_entry, sql_ex, "message", sizeof("message") - 1,
+ message TSRMLS_CC);
+ }
+
+ if (sqlstate) {
+ zend_update_property_string(mysqli_exception_class_entry, sql_ex, "sqlstate", sizeof("sqlstate") - 1,
+ sqlstate TSRMLS_CC);
+ } else {
+ zend_update_property_string(mysqli_exception_class_entry, sql_ex, "sqlstate", sizeof("sqlstate") - 1,
+ "00000" TSRMLS_CC);
+ }
+
+ efree(message);
+ zend_update_property_long(mysqli_exception_class_entry, sql_ex, "code", sizeof("code") - 1, errorno TSRMLS_CC);
+
+ zend_throw_exception_object(sql_ex);
+}
+
diff --git a/ext/mysqli/mysqli_fe.c b/ext/mysqli/mysqli_fe.c
index 35c43e6c4e..eddea9de37 100644
--- a/ext/mysqli/mysqli_fe.c
+++ b/ext/mysqli/mysqli_fe.c
@@ -65,11 +65,10 @@ function_entry mysqli_functions[] = {
PHP_FE(mysqli_disable_reads_from_master, NULL)
PHP_FE(mysqli_disable_rpl_parse, NULL)
PHP_FE(mysqli_dump_debug_info, NULL)
-#ifdef HAVE_EMBEDDED_MYSQLI
- PHP_FE(mysqli_embedded_connect, NULL)
-#endif
PHP_FE(mysqli_enable_reads_from_master, NULL)
PHP_FE(mysqli_enable_rpl_parse, NULL)
+ PHP_FE(mysqli_embedded_server_end, NULL)
+ PHP_FE(mysqli_embedded_server_start, NULL)
PHP_FE(mysqli_errno, NULL)
PHP_FE(mysqli_error, NULL)
PHP_FE(mysqli_stmt_execute, NULL)
@@ -132,10 +131,6 @@ function_entry mysqli_functions[] = {
PHP_FE(mysqli_stmt_reset, NULL)
PHP_FE(mysqli_stmt_param_count, NULL)
PHP_FE(mysqli_send_query, NULL)
-#ifdef HAVE_EMBEDDED_MYSQLI
- PHP_FE(mysqli_server_end, NULL)
- PHP_FE(mysqli_server_init, NULL)
-#endif
PHP_FE(mysqli_slave_query, NULL)
PHP_FE(mysqli_sqlstate, NULL)
PHP_FE(mysqli_ssl_set, NULL)
@@ -196,6 +191,7 @@ function_entry mysqli_link_methods[] = {
PHP_FALIAS(enable_rpl_parse,mysqli_enable_rpl_parse,NULL)
PHP_FALIAS(get_client_info,mysqli_get_client_info,NULL)
PHP_FALIAS(get_server_info,mysqli_get_server_info,NULL)
+ PHP_FALIAS(get_warnings, mysqli_warning_construct, NULL)
PHP_FALIAS(init,mysqli_init,NULL)
PHP_FALIAS(kill,mysqli_kill,NULL)
PHP_FALIAS(set_local_infile_default,mysqli_set_local_infile_default,NULL)
@@ -265,6 +261,7 @@ function_entry mysqli_stmt_methods[] = {
PHP_FALIAS(data_seek,mysqli_stmt_data_seek,NULL)
PHP_FALIAS(execute,mysqli_stmt_execute,NULL)
PHP_FALIAS(fetch,mysqli_stmt_fetch,NULL)
+ PHP_FALIAS(get_warnings, mysqli_warning_construct, NULL)
PHP_FALIAS(result_metadata, mysqli_stmt_result_metadata,NULL)
PHP_FALIAS(num_rows, mysqli_stmt_num_rows,NULL)
PHP_FALIAS(send_long_data,mysqli_stmt_send_long_data,NULL)
diff --git a/ext/mysqli/mysqli_nonapi.c b/ext/mysqli/mysqli_nonapi.c
index 805187231e..566df49b1f 100644
--- a/ext/mysqli/mysqli_nonapi.c
+++ b/ext/mysqli/mysqli_nonapi.c
@@ -74,15 +74,23 @@ PHP_FUNCTION(mysqli_connect)
RETURN_FALSE;
}
+#ifdef HAVE_EMBEDDED_MYSQLI
+ if (hostname && strlen(hostname)) {
+ unsigned int external=1;
+ mysql_options(mysql->mysql, MYSQL_OPT_USE_REMOTE_CONNECTION, (char *)&external);
+ } else {
+ mysql_options(mysql->mysql, MYSQL_OPT_USE_EMBEDDED_CONNECTION, 0);
+ }
+#endif
+
if (mysql_real_connect(mysql->mysql,hostname,username,passwd,dbname,port,socket,CLIENT_MULTI_RESULTS) == NULL) {
/* Save error messages */
- MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
+ php_mysqli_throw_sql_exception( mysql->mysql->net.sqlstate, mysql->mysql->net.last_errno TSRMLS_CC,
+ mysql->mysql->net.last_error);
+
php_mysqli_set_error(mysql_errno(mysql->mysql), (char *) mysql_error(mysql->mysql) TSRMLS_CC);
- if (!(MyG(report_mode) & MYSQLI_REPORT_ERROR)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", mysql_error(mysql->mysql));
- }
/* free mysql structure */
mysql_close(mysql->mysql);
RETURN_FALSE;
@@ -108,60 +116,6 @@ PHP_FUNCTION(mysqli_connect)
}
/* }}} */
-#ifdef HAVE_EMBEDDED_MYSQLI
-/* {{{ proto object mysqli_embedded_connect(void)
- Open a connection to a embedded mysql server */
-PHP_FUNCTION(mysqli_embedded_connect)
-{
- MY_MYSQL *mysql;
- MYSQLI_RESOURCE *mysqli_resource;
- zval *object = getThis();
- char *dbname = NULL;
- int dblen = 0;
-
- if (!MyG(embedded)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Embedded server was not initialized.");
- RETURN_FALSE;
- }
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &dbname, &dblen) == FAILURE) {
- return;
- }
-
- mysql = (MY_MYSQL *) calloc(1, sizeof(MY_MYSQL));
-
- if (!(mysql = mysql_init(NULL))) {
- efree(mysql);
- RETURN_FALSE;
- }
-
- if (mysql_real_connect(mysql, NULL, NULL, NULL, dbname, 0, NULL, 0) == NULL) {
- MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
- php_mysqli_set_error(mysql_errno(mysql->mysql), (char *) mysql_error(mysql->mysql) TSRMLS_CC);
-
- if (!(MyG(report_mode) & MYSQLI_REPORT_ERROR)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", mysql_error(mysql->mysql));
- }
- /* free mysql structure */
- mysql_close(mysql->mysql);
- efree(mysql);
- RETURN_FALSE;
- }
-
- php_mysqli_set_error(mysql_errno(mysql->mysql), (char *) mysql_error(mysql->mysql) TSRMLS_CC);
-
- mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
- mysqli_resource->ptr = (void *)mysql;
-
- if (!object) {
- MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_link_class_entry);
- } else {
- ((mysqli_object *) zend_object_store_get_object(object TSRMLS_CC))->ptr = mysqli_resource;
- }
-}
-/* }}} */
-#endif
-
/* {{{ proto int mysqli_connect_errno(void)
Returns the numerical value of the error message from last connect command */
PHP_FUNCTION(mysqli_connect_errno)
@@ -278,6 +232,8 @@ PHP_FUNCTION(mysqli_query)
result = (resultmode == MYSQLI_USE_RESULT) ? mysql_use_result(mysql->mysql) : mysql_store_result(mysql->mysql);
if (!result) {
+ php_mysqli_throw_sql_exception(mysql->mysql->net.sqlstate, mysql->mysql->net.last_errno TSRMLS_CC,
+ mysql->mysql->net.last_error);
RETURN_FALSE;
}
diff --git a/ext/mysqli/mysqli_prop.c b/ext/mysqli/mysqli_prop.c
index 714e75935e..53c392f06b 100644
--- a/ext/mysqli/mysqli_prop.c
+++ b/ext/mysqli/mysqli_prop.c
@@ -225,6 +225,7 @@ MYSQLI_MAP_PROPERTY_FUNC_LONG(stmt_errno_read, mysql_stmt_errno, MYSQLI_GET_STMT
MYSQLI_MAP_PROPERTY_FUNC_STRING(stmt_error_read, mysql_stmt_error, MYSQLI_GET_STMT());
MYSQLI_MAP_PROPERTY_FUNC_STRING(stmt_sqlstate_read, mysql_stmt_sqlstate, MYSQLI_GET_STMT());
+/* }}} */
mysqli_property_entry mysqli_link_property_entries[] = {
{"affected_rows", link_affected_rows_read, NULL},
{"client_info", link_client_info_read, NULL},
diff --git a/ext/mysqli/mysqli_report.c b/ext/mysqli/mysqli_report.c
index a21d21a9f0..e7d5202b71 100644
--- a/ext/mysqli/mysqli_report.c
+++ b/ext/mysqli/mysqli_report.c
@@ -46,7 +46,7 @@ PHP_FUNCTION(mysqli_report)
/* {{{ void php_mysqli_report_error(char *sqlstate, int errorno, char *error) */
void php_mysqli_report_error(char *sqlstate, int errorno, char *error TSRMLS_DC) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error (%s/%d): %s", sqlstate, errorno, error);
+ php_mysqli_throw_sql_exception(sqlstate, errorno TSRMLS_CC, error);
}
/* }}} */
@@ -61,7 +61,7 @@ void php_mysqli_report_index(char *query, unsigned int status TSRMLS_DC) {
} else {
return;
}
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s used in query/prepared statement %s", index, query);
+ php_mysqli_throw_sql_exception("00000", 0 TSRMLS_CC, "%s used in query/prepared statement %s", index, query);
}
/* }}} */
diff --git a/ext/mysqli/mysqli_warning.c b/ext/mysqli/mysqli_warning.c
new file mode 100644
index 0000000000..9114d7b493
--- /dev/null
+++ b/ext/mysqli/mysqli_warning.c
@@ -0,0 +1,172 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2004 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.0 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_0.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Georg Richter <georg@php.net> |
+ +----------------------------------------------------------------------+
+
+*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <signal.h>
+
+#include "php.h"
+#include "php_ini.h"
+#include "ext/standard/info.h"
+#include "php_mysqli.h"
+
+/* {{{ void php_clear_warnings() */
+void php_clear_warnings(MYSQLI_WARNING *w)
+{
+ if (w->result) {
+ mysql_free_result(w->result);
+ }
+ efree(w);
+}
+/* }}} */
+
+/* {{{ void php_get_warnings(MYSQL *mysql) */
+MYSQLI_WARNING *php_get_warnings(MYSQL *mysql)
+{
+ MYSQLI_WARNING *w;
+ int cwarnings;
+
+ if (!(cwarnings = mysql_warning_count(mysql))) {
+ return NULL;
+ }
+
+ if (mysql_query(mysql, "SHOW WARNINGS")) {
+ return NULL;
+ }
+
+ if (!(w = (MYSQLI_WARNING *)ecalloc(sizeof(MYSQLI_WARNING), 1))) {
+ return NULL;
+ }
+
+ w->warning_count = cwarnings;
+ w->result = mysql_store_result(mysql);
+ if (!(w->row = mysql_fetch_row(w->result))) {
+ mysql_free_result(w->result);
+ efree(w);
+ return NULL;
+ }
+
+ return w;
+}
+/* }}} */
+
+/* {{{ mysqli_warning::__construct */
+ZEND_FUNCTION(mysqli_warning_construct)
+{
+ MYSQL *mysql = NULL;
+ MYSQLI_WARNING *w;
+ MYSQLI_RESOURCE *mysqli_resource;
+ mysqli_object *obj;
+
+ if (!getThis()) {
+ RETURN_FALSE;
+ }
+
+ obj = (mysqli_object *)zend_objects_get_address(getThis() TSRMLS_CC);
+
+ if (obj->zo.ce == mysqli_link_class_entry) {
+ mysql = (MYSQL *)((MY_MYSQL *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr)->mysql;
+ } else if (obj->zo.ce == mysqli_stmt_class_entry) {
+ mysql = (MYSQL *)((MY_STMT *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr)->stmt->mysql;
+ }
+
+ if ((w = php_get_warnings(mysql))) {
+ mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
+ mysqli_resource->ptr = (void *)w;
+ obj->valid = 1;
+
+ MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_warning_class_entry);
+ } else {
+ RETURN_FALSE;
+ }
+}
+/* }}} */
+
+/* {{{ bool mysqli_warning::next */
+ZEND_FUNCTION(mysqli_warning_next) {
+ MYSQLI_WARNING *w;
+ zval *mysql_warning;
+ mysqli_object *obj = (mysqli_object *)zend_objects_get_address(getThis() TSRMLS_CC);
+
+ if (obj->valid) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
+ &mysql_warning, mysqli_warning_class_entry) == FAILURE) {
+ return;
+ }
+
+ MYSQLI_FETCH_RESOURCE(w, MYSQLI_WARNING *, &mysql_warning, "mysqli_warning");
+
+ if (w->warning_count && (w->row = mysql_fetch_row(w->result))) {
+ RETURN_TRUE;
+ }
+ }
+ RETURN_FALSE;
+}
+/* }}} */
+
+/* {{{ property mysqli_warning_error */
+int mysqli_warning_error(mysqli_object *obj, zval **retval TSRMLS_DC)
+{
+ MYSQLI_WARNING *w;
+
+ ALLOC_ZVAL(*retval);
+ w = obj->valid ? (MYSQLI_WARNING *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr : NULL;
+
+ if (w && w->row && w->row[2]) {
+ ZVAL_STRING(*retval, w->row[2], 1);
+ } else {
+ ZVAL_NULL(*retval);
+ }
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ property mysqli_warning_error */
+int mysqli_warning_errno(mysqli_object *obj, zval **retval TSRMLS_DC)
+{
+ MYSQLI_WARNING *w;
+
+ ALLOC_ZVAL(*retval);
+ w = obj->valid ? (MYSQLI_WARNING *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr : NULL;
+
+ if (w && w->row && w->row[1]) {
+ ZVAL_LONG(*retval, atoi(w->row[1]));
+ } else {
+ ZVAL_NULL(*retval);
+ }
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ mysqli_warning_methods[]
+ */
+function_entry mysqli_warning_methods[] = {
+ PHP_FALIAS(__construct,mysqli_warning_construct, NULL)
+ PHP_FALIAS(next,mysqli_warning_next,NULL)
+ {NULL, NULL, NULL}
+};
+/* }}} */
+
+
+mysqli_property_entry mysqli_warning_property_entries[] = {
+ {"error", mysqli_warning_error, NULL},
+ {"errno", mysqli_warning_errno, NULL},
+ {NULL, NULL, NULL}
+};
diff --git a/ext/mysqli/php_mysqli.h b/ext/mysqli/php_mysqli.h
index e259bd6879..d459809a29 100644
--- a/ext/mysqli/php_mysqli.h
+++ b/ext/mysqli/php_mysqli.h
@@ -31,6 +31,8 @@
#ifndef PHP_MYSQLI_H
#define PHP_MYSQLI_H
+#define MYSQLI_VERSION_ID 101008
+
typedef struct {
ulong buflen;
char *val;
@@ -68,6 +70,12 @@ typedef struct {
void *info; /* additional buffer */
} MYSQLI_RESOURCE;
+typedef struct {
+ MYSQL_RES *result; /* stored result set from SHOW WARNINGS */
+ MYSQL_ROW row;
+ int warning_count; /* number of warnings */
+} MYSQLI_WARNING;
+
typedef struct _mysqli_object {
zend_object zo;
void *ptr;
@@ -78,7 +86,7 @@ typedef struct _mysqli_object {
typedef struct _mysqli_property_entry {
char *pname;
int (*r_func)(mysqli_object *obj, zval **retval TSRMLS_DC);
- int (*w_func)(mysqli_object *obj, zval **retval TSRMLS_DC);
+ int (*w_func)(mysqli_object *obj, zval *value TSRMLS_DC);
} mysqli_property_entry;
typedef struct {
@@ -105,13 +113,20 @@ extern function_entry mysqli_functions[];
extern function_entry mysqli_link_methods[];
extern function_entry mysqli_stmt_methods[];
extern function_entry mysqli_result_methods[];
+extern function_entry mysqli_driver_methods[];
+extern function_entry mysqli_warning_methods[];
+extern function_entry mysqli_exception_methods[];
+
extern mysqli_property_entry mysqli_link_property_entries[];
extern mysqli_property_entry mysqli_result_property_entries[];
extern mysqli_property_entry mysqli_stmt_property_entries[];
+extern mysqli_property_entry mysqli_driver_property_entries[];
+extern mysqli_property_entry mysqli_warning_property_entries[];
extern void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flag, int into_object);
extern void php_clear_stmt_bind(MY_STMT *stmt);
-void php_clear_mysql(MY_MYSQL *);
+extern void php_clear_mysql(MY_MYSQL *);
+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(char *sqlstate, int errorno, char *error TSRMLS_DC);
extern void php_mysqli_report_index(char *query, unsigned int status TSRMLS_DC);
@@ -120,14 +135,17 @@ 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, ...);
zend_class_entry *mysqli_link_class_entry;
zend_class_entry *mysqli_stmt_class_entry;
zend_class_entry *mysqli_result_class_entry;
+zend_class_entry *mysqli_driver_class_entry;
+zend_class_entry *mysqli_warning_class_entry;
+zend_class_entry *mysqli_exception_class_entry;
-zend_class_entry _mysqli_link_class_entry;
-zend_class_entry _mysqli_stmt_class_entry;
-zend_class_entry _mysqli_result_class_entry;
+#ifdef HAVE_SPL
+extern PHPAPI zend_class_entry *spl_ce_RuntimeException;
+#endif
PHP_MYSQLI_EXPORT(zend_object_value) mysqli_objects_new(zend_class_entry * TSRMLS_DC);
@@ -142,9 +160,10 @@ PHP_MYSQLI_EXPORT(zend_object_value) mysqli_objects_new(zend_class_entry * TSRML
}
#define REGISTER_MYSQLI_CLASS_ENTRY(name, mysqli_entry, class_functions) { \
- INIT_CLASS_ENTRY(_##mysqli_entry,name,class_functions); \
- _##mysqli_entry.create_object = mysqli_objects_new; \
- mysqli_entry = zend_register_internal_class(&_##mysqli_entry TSRMLS_CC); \
+ zend_class_entry ce; \
+ INIT_CLASS_ENTRY(ce, name,class_functions); \
+ ce.create_object = mysqli_objects_new; \
+ mysqli_entry = zend_register_internal_class(&ce TSRMLS_CC); \
} \
#define MYSQLI_REGISTER_RESOURCE_EX(__ptr, __zval, __ce) \
@@ -210,7 +229,7 @@ PHP_MYSQLI_EXPORT(zend_object_value) mysqli_objects_new(zend_class_entry * TSRML
{ \
int i = 0; \
while (b[i].pname != NULL) { \
- mysqli_add_property(a, b[i].pname, (mysqli_read_t)b[i].r_func, NULL TSRMLS_CC); \
+ mysqli_add_property(a, b[i].pname, (mysqli_read_t)b[i].r_func, (mysqli_write_t)b[i].w_func TSRMLS_CC); \
i++; \
}\
}
@@ -241,9 +260,10 @@ PHP_MYSQLI_EXPORT(zend_object_value) mysqli_objects_new(zend_class_entry * TSRML
/*** REPORT MODES ***/
#define MYSQLI_REPORT_OFF 0
-#define MYSQLI_REPORT_INDEX 1
-#define MYSQLI_REPORT_ERROR 2
-#define MYSQLI_REPORT_CLOSE 4
+#define MYSQLI_REPORT_ERROR 1
+#define MYSQLI_REPORT_STRICT 2
+#define MYSQLI_REPORT_INDEX 4
+#define MYSQLI_REPORT_CLOSE 8
#define MYSQLI_REPORT_ALL 255
#define MYSQLI_REPORT_MYSQL_ERROR(mysql) \
@@ -282,9 +302,6 @@ PHP_FUNCTION(mysqli_debug);
PHP_FUNCTION(mysqli_disable_reads_from_master);
PHP_FUNCTION(mysqli_disable_rpl_parse);
PHP_FUNCTION(mysqli_dump_debug_info);
-#ifdef HAVE_EMBEDDED_MYSQLI
-PHP_FUNCTION(mysqli_embedded_connect);
-#endif
PHP_FUNCTION(mysqli_enable_reads_from_master);
PHP_FUNCTION(mysqli_enable_rpl_parse);
PHP_FUNCTION(mysqli_errno);
@@ -347,10 +364,8 @@ PHP_FUNCTION(mysqli_stmt_fetch);
PHP_FUNCTION(mysqli_stmt_param_count);
PHP_FUNCTION(mysqli_stmt_send_long_data);
PHP_FUNCTION(mysqli_send_query);
-#ifdef HAVE_EMBEDDED_MYSQLI
-PHP_FUNCTION(mysqli_server_init);
-PHP_FUNCTION(mysqli_server_end);
-#endif
+PHP_FUNCTION(mysqli_embedded_server_end);
+PHP_FUNCTION(mysqli_embedded_server_start);
PHP_FUNCTION(mysqli_slave_query);
PHP_FUNCTION(mysqli_sqlstate);
PHP_FUNCTION(mysqli_ssl_set);
@@ -374,6 +389,8 @@ PHP_FUNCTION(mysqli_warning_count);
ZEND_FUNCTION(mysqli_stmt_construct);
ZEND_FUNCTION(mysqli_result_construct);
+ZEND_FUNCTION(mysqli_driver_construct);
+ZEND_FUNCTION(mysqli_warning_construct);
ZEND_BEGIN_MODULE_GLOBALS(mysqli)
long default_link;
@@ -385,14 +402,13 @@ ZEND_BEGIN_MODULE_GLOBALS(mysqli)
char *default_socket;
char *default_pw;
int reconnect;
+ int strict;
long error_no;
char *error_msg;
int report_mode;
HashTable *report_ht;
unsigned int multi_query;
-#ifdef HAVE_EMBEDDED_MYSQLI
unsigned int embedded;
-#endif
ZEND_END_MODULE_GLOBALS(mysqli)
diff --git a/ext/mysqli/tests/001.phpt b/ext/mysqli/tests/001.phpt
index 880325bb5a..3f2f3c2d31 100644
--- a/ext/mysqli/tests/001.phpt
+++ b/ext/mysqli/tests/001.phpt
@@ -2,13 +2,14 @@
mysqli connect
--SKIPIF--
<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifemb.inc'); ?>
--FILE--
<?php
include "connect.inc";
$dbname = "test";
$test = "";
-
+
/*** test mysqli_connect localhost:port ***/
$link = mysqli_connect($host, $user, $passwd, "", 3306);
$test .= ($link) ? "1" : "0";
diff --git a/ext/mysqli/tests/014.phpt b/ext/mysqli/tests/014.phpt
index 69c347b88b..f8c02dba69 100644
--- a/ext/mysqli/tests/014.phpt
+++ b/ext/mysqli/tests/014.phpt
@@ -1,7 +1,7 @@
--TEST--
mysqli autocommit/commit/rollback
--SKIPIF--
-<?php
+<?php
include "connect.inc";
$link = mysqli_connect($host, $user, $passwd);
$result = mysqli_query($link, "SHOW VARIABLES LIKE 'have_innodb'");
diff --git a/ext/mysqli/tests/017.phpt b/ext/mysqli/tests/017.phpt
index 7f51ca4b91..54d11ef719 100644
--- a/ext/mysqli/tests/017.phpt
+++ b/ext/mysqli/tests/017.phpt
@@ -2,6 +2,7 @@
mysqli fetch functions
--SKIPIF--
<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifemb.inc'); ?>
--FILE--
<?php
include "connect.inc";
diff --git a/ext/mysqli/tests/033.phpt b/ext/mysqli/tests/033.phpt
index 3a56b5c678..5dddcc10c9 100644
--- a/ext/mysqli/tests/033.phpt
+++ b/ext/mysqli/tests/033.phpt
@@ -2,6 +2,7 @@
function test: mysqli_get_host_info
--SKIPIF--
<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifemb.inc'); ?>
--FILE--
<?php
include "connect.inc";
diff --git a/ext/mysqli/tests/034.phpt b/ext/mysqli/tests/034.phpt
index 47c99f07e5..468861c3c2 100644
--- a/ext/mysqli/tests/034.phpt
+++ b/ext/mysqli/tests/034.phpt
@@ -2,6 +2,7 @@
function test: mysqli_get_proto_info
--SKIPIF--
<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifemb.inc'); ?>
--FILE--
<?php
include "connect.inc";
diff --git a/ext/mysqli/tests/041.phpt b/ext/mysqli/tests/041.phpt
index e78c60a956..d6a9f954d0 100644
--- a/ext/mysqli/tests/041.phpt
+++ b/ext/mysqli/tests/041.phpt
@@ -15,8 +15,8 @@ function test: mysqli_warning_count()
mysqli_query($link, "DROP TABLE IF EXISTS test_warnings");
mysqli_query($link, "CREATE TABLE test_warnings (a int not null");
+ mysqli_query($link, "INSERT INTO test_warnings VALUES (NULL)");
- mysqli_query($link, "INSERT INTO test_warnings VALUES (1),(2),(NULL)");
$num = mysqli_warning_count($link);
var_dump($num);
diff --git a/ext/mysqli/tests/045.phpt b/ext/mysqli/tests/045.phpt
index 5a6efeafb7..2f9490c282 100644
--- a/ext/mysqli/tests/045.phpt
+++ b/ext/mysqli/tests/045.phpt
@@ -17,6 +17,7 @@ mysqli_bind_result (SHOW)
?>
--SKIPIF--
<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifemb.inc'); ?>
--FILE--
<?php
include "connect.inc";
diff --git a/ext/mysqli/tests/047.phpt b/ext/mysqli/tests/047.phpt
index d6ccb0df37..8663e8a641 100644
--- a/ext/mysqli/tests/047.phpt
+++ b/ext/mysqli/tests/047.phpt
@@ -31,7 +31,7 @@ mysqli_get_metadata
--EXPECTF--
array(2) {
[0]=>
- object(stdClass)#4 (11) {
+ object(stdClass)#5 (11) {
["name"]=>
string(3) "foo"
["orgname"]=>
@@ -56,7 +56,7 @@ array(2) {
int(0)
}
[1]=>
- object(stdClass)#5 (11) {
+ object(stdClass)#6 (11) {
["name"]=>
string(3) "bar"
["orgname"]=>
diff --git a/ext/mysqli/tests/049.phpt b/ext/mysqli/tests/049.phpt
index 13ea5594c3..8d16c3d4c7 100644
--- a/ext/mysqli/tests/049.phpt
+++ b/ext/mysqli/tests/049.phpt
@@ -2,6 +2,7 @@
mysql_fetch_row (OO-Style)
--SKIPIF--
<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifemb.inc'); ?>
--FILE--
<?php
include "connect.inc";
diff --git a/ext/mysqli/tests/061.phpt b/ext/mysqli/tests/061.phpt
index 9c278353c6..caee2e49bb 100644
--- a/ext/mysqli/tests/061.phpt
+++ b/ext/mysqli/tests/061.phpt
@@ -2,6 +2,7 @@
local infile handler
--SKIPIF--
<?php require_once('skipif.inc'); ?>
+<?php require_once('skipifemb.inc'); ?>
--FILE--
<?php
include "connect.inc";
diff --git a/ext/mysqli/tests/connect.inc b/ext/mysqli/tests/connect.inc
index aa1d30a17e..decdd87d51 100644
--- a/ext/mysqli/tests/connect.inc
+++ b/ext/mysqli/tests/connect.inc
@@ -3,8 +3,24 @@
/* default values are localhost, root and empty password
Change the values if you use another configuration */
- $host = "localhost";
- $user = "root";
- $passwd = "";
+ $driver = new mysqli_driver;
+
+ if (!$driver->embedded) {
+ $host = "localhost";
+ $user = "root";
+ $passwd = "";
+
+ $driver->embedded_server_start(FALSE, NULL, NULL);
+ } else {
+ $path = realpath('./ext/mysqli/tests');
+ $host = $user = $passwd = NULL;
+ $args = array(
+ "--datadir=$path",
+ "--innodb_data_home_dir=$path",
+ "--innodb_data_file_path=ibdata1:10M:autoextend",
+ "--log-error=$path/testrun.log"
+ );
+ $driver->embedded_server_start(TRUE, $args, NULL);
+ }
?>
diff --git a/ext/mysqli/tests/skipif.inc b/ext/mysqli/tests/skipif.inc
index eded86dc85..68a9c7cf0e 100644
--- a/ext/mysqli/tests/skipif.inc
+++ b/ext/mysqli/tests/skipif.inc
@@ -1 +1,4 @@
-<?php if (!extension_loaded('mysqli')) die('skip mysqli extension not available');?>
+<?php
+ if (!extension_loaded('mysqli'))
+ die('skip mysqli extension not available');
+?>
diff --git a/ext/mysqli/tests/skipifemb.inc b/ext/mysqli/tests/skipifemb.inc
new file mode 100644
index 0000000000..298c7219a6
--- /dev/null
+++ b/ext/mysqli/tests/skipifemb.inc
@@ -0,0 +1,5 @@
+<?php
+ $driver = new mysqli_driver();
+ if ($driver->embedded)
+ die("skip test doesn't run with embedded server");
+?>