summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXinchen Hui <laruence@gmail.com>2014-03-23 11:30:09 +0800
committerXinchen Hui <laruence@gmail.com>2014-03-23 13:23:25 +0800
commitadcfee7b07ce96272349e6a17892151a150658bb (patch)
treec688442cdb6a938e66ffe994553459e66863450c
parentf2a598393f6dbd88001f277843433a475915663b (diff)
downloadphp-git-adcfee7b07ce96272349e6a17892151a150658bb.tar.gz
Refactor ext/mysql
-rw-r--r--Zend/zend_list.c2
-rw-r--r--ext/mysql/php_mysql.c811
-rw-r--r--ext/mysql/php_mysql_structs.h2
-rw-r--r--ext/mysql/tests/mysql_data_seek.phpt2
-rw-r--r--ext/mysql/tests/mysql_db_name.phpt2
-rw-r--r--ext/mysql/tests/mysql_errno.phpt2
-rw-r--r--ext/mysql/tests/mysql_error.phpt2
-rw-r--r--ext/mysql/tests/mysql_fetch_array.phpt2
-rw-r--r--ext/mysql/tests/mysql_fetch_assoc.phpt2
-rw-r--r--ext/mysql/tests/mysql_fetch_field.phpt2
-rw-r--r--ext/mysql/tests/mysql_fetch_lengths.phpt2
-rw-r--r--ext/mysql/tests/mysql_fetch_object.phpt2
-rw-r--r--ext/mysql/tests/mysql_fetch_row.phpt2
-rw-r--r--ext/mysql/tests/mysql_field_flags.phpt2
-rw-r--r--ext/mysql/tests/mysql_field_len.phpt2
-rw-r--r--ext/mysql/tests/mysql_field_name.phpt2
-rw-r--r--ext/mysql/tests/mysql_field_seek.phpt2
-rw-r--r--ext/mysql/tests/mysql_field_table.phpt2
-rw-r--r--ext/mysql/tests/mysql_field_type.phpt2
-rw-r--r--ext/mysql/tests/mysql_free_result.phpt2
-rw-r--r--ext/mysql/tests/mysql_insert_id.phpt2
-rw-r--r--ext/mysql/tests/mysql_num_fields.phpt2
-rw-r--r--ext/mysql/tests/mysql_num_rows.phpt2
-rw-r--r--ext/mysql/tests/mysql_ping.phpt2
-rw-r--r--ext/mysql/tests/mysql_query.phpt2
-rw-r--r--ext/mysql/tests/mysql_result.phpt2
-rw-r--r--ext/mysql/tests/mysql_select_db.phpt2
-rw-r--r--ext/mysql/tests/mysql_stat.phpt2
-rw-r--r--ext/mysql/tests/mysql_tablename.phpt2
-rw-r--r--ext/mysql/tests/mysql_thread_id.phpt2
-rw-r--r--ext/mysql/tests/mysql_unbuffered_query.phpt2
-rw-r--r--ext/mysql/tests/setupdefault.inc2
32 files changed, 428 insertions, 445 deletions
diff --git a/Zend/zend_list.c b/Zend/zend_list.c
index f7cbfac89f..42450695d1 100644
--- a/Zend/zend_list.c
+++ b/Zend/zend_list.c
@@ -212,7 +212,7 @@ void plist_entry_destructor(zval *zv)
int zend_init_rsrc_list(TSRMLS_D)
{
if (zend_hash_init(&EG(regular_list), 0, NULL, list_entry_destructor, 0)==SUCCESS) {
- EG(regular_list).nNextFreeElement=1; /* we don't want resource id 0 */
+ EG(regular_list).nNextFreeElement = 1; /* we don't want resource id 0 */
return SUCCESS;
} else {
return FAILURE;
diff --git a/ext/mysql/php_mysql.c b/ext/mysql/php_mysql.c
index a00e98fbbc..eb34d442ac 100644
--- a/ext/mysql/php_mysql.c
+++ b/ext/mysql/php_mysql.c
@@ -121,7 +121,7 @@ static PHP_GINIT_FUNCTION(mysql);
typedef struct _php_mysql_conn {
MYSQL *conn;
- int active_result_id;
+ zend_resource *active_result_res;
int multi_query;
} php_mysql_conn;
@@ -363,46 +363,49 @@ ZEND_GET_MODULE(mysql)
void timeout(int sig);
-#define CHECK_LINK(link) { if (link==-1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "A link to the server could not be established"); RETURN_FALSE; } }
+#define CHECK_LINK(link) { if (link == NULL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "A link to the server could not be established"); RETURN_FALSE; } }
#if defined(MYSQL_USE_MYSQLND)
-#define PHPMY_UNBUFFERED_QUERY_CHECK() \
-{\
- if (mysql->active_result_id) { \
- do { \
- int type; \
- MYSQL_RES *_mysql_result; \
- \
- _mysql_result = (MYSQL_RES *) zend_list_find(mysql->active_result_id, &type); \
- if (_mysql_result && type==le_result) { \
- if (mysql_result_is_unbuffered(_mysql_result) && !mysql_eof(_mysql_result)) { \
- php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Function called without first fetching all rows from a previous unbuffered query"); \
- } \
- zend_list_delete(mysql->active_result_id); \
- mysql->active_result_id = 0; \
- } \
- } while(0); \
- }\
+#define PHPMY_UNBUFFERED_QUERY_CHECK() \
+{ \
+ if (mysql->active_result_res) { \
+ do { \
+ MYSQL_RES *_mysql_result; \
+ _mysql_result = (MYSQL_RES *)mysql->active_result_res->ptr; \
+ if (_mysql_result && \
+ mysql->active_result_res->type == le_result) { \
+ if (mysql_result_is_unbuffered(_mysql_result) && \
+ !mysql_eof(_mysql_result)) { \
+ php_error_docref(NULL TSRMLS_CC, E_NOTICE, \
+ "Function called without first fetching all" \
+ "rows from a previous unbuffered query"); \
+ } \
+ zend_list_close(mysql->active_result_res); \
+ mysql->active_result_res = NULL; \
+ } \
+ } while(0); \
+ } \
}
#else
-#define PHPMY_UNBUFFERED_QUERY_CHECK() \
-{ \
- if (mysql->active_result_id) { \
- do { \
- int type; \
- MYSQL_RES *mysql_result; \
- \
- mysql_result = (MYSQL_RES *) zend_list_find(mysql->active_result_id, &type); \
- if (mysql_result && type==le_result) { \
- if (!mysql_eof(mysql_result)) { \
- php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Function called without first fetching all rows from a previous unbuffered query"); \
- while (mysql_fetch_row(mysql_result)); \
- } \
- zend_list_delete(mysql->active_result_id); \
- mysql->active_result_id = 0; \
- } \
- } while(0); \
- } \
+#define PHPMY_UNBUFFERED_QUERY_CHECK() \
+{ \
+ if (mysql->active_result_res) { \
+ do { \
+ MYSQL_RES *mysql_result; \
+ mysql_result = (MYSQL_RES *) mysql->active_result_res->ptr; \
+ if (mysql_result && \
+ mysql->active_result_res->type == le_result) { \
+ if (!mysql_eof(mysql_result)) { \
+ php_error_docref(NULL TSRMLS_CC, E_NOTICE, \
+ "Function called without first fetching " \
+ "all rows from a previous unbuffered query"); \
+ while (mysql_fetch_row(mysql_result)); \
+ } \
+ zend_list_close(mysql->active_result_res); \
+ mysql->active_result_res = NULL; \
+ } \
+ } while(0); \
+ } \
}
#endif
@@ -410,7 +413,7 @@ void timeout(int sig);
* This wrapper is required since mysql_free_result() returns an integer, and
* thus, cannot be used directly
*/
-static void _free_mysql_result(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+static void _free_mysql_result(zend_resource *rsrc TSRMLS_DC)
{
MYSQL_RES *mysql_result = (MYSQL_RES *)rsrc->ptr;
@@ -421,13 +424,15 @@ static void _free_mysql_result(zend_rsrc_list_entry *rsrc TSRMLS_DC)
/* {{{ php_mysql_set_default_link
*/
-static void php_mysql_set_default_link(int id TSRMLS_DC)
+static void php_mysql_set_default_link(zend_resource *link TSRMLS_DC)
{
- if (MySG(default_link) != -1) {
- zend_list_delete(MySG(default_link));
+ if (MySG(default_link) != NULL) {
+ if (--(MySG(default_link)->gc.refcount) == 0) {
+ zend_list_delete(MySG(default_link));
+ }
}
- MySG(default_link) = id;
- zend_list_addref(id);
+ ++link->gc.refcount;
+ MySG(default_link) = link;
}
/* }}} */
@@ -447,10 +452,10 @@ static int php_mysql_select_db(php_mysql_conn *mysql, char *db TSRMLS_DC)
/* {{{ _close_mysql_link
*/
-static void _close_mysql_link(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+static void _close_mysql_link(zend_resource *rsrc TSRMLS_DC)
{
php_mysql_conn *link = (php_mysql_conn *)rsrc->ptr;
- void (*handler) (int);
+ void (*handler)(int);
handler = signal(SIGPIPE, SIG_IGN);
mysql_close(link->conn);
@@ -462,7 +467,7 @@ static void _close_mysql_link(zend_rsrc_list_entry *rsrc TSRMLS_DC)
/* {{{ _close_mysql_plink
*/
-static void _close_mysql_plink(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+static void _close_mysql_plink(zend_resource *rsrc TSRMLS_DC)
{
php_mysql_conn *link = (php_mysql_conn *)rsrc->ptr;
void (*handler) (int);
@@ -531,7 +536,7 @@ static PHP_GINIT_FUNCTION(mysql)
#ifdef MYSQL_USE_MYSQLND
#include "ext/mysqlnd/mysqlnd_reverse_api.h"
-static MYSQLND * mysql_convert_zv_to_mysqlnd(zval * zv TSRMLS_DC)
+static MYSQLND *mysql_convert_zv_to_mysqlnd(zval *zv TSRMLS_DC)
{
php_mysql_conn *mysql;
@@ -540,7 +545,7 @@ static MYSQLND * mysql_convert_zv_to_mysqlnd(zval * zv TSRMLS_DC)
return NULL;
}
- mysql = (php_mysql_conn *)zend_fetch_resource(&zv TSRMLS_CC, -1, "MySQL-Link", NULL, 2, le_link, le_plink);
+ mysql = zend_fetch_resource(zv TSRMLS_CC, -1, "MySQL-Link", NULL, 2, le_link, le_plink);
if (!mysql) {
return NULL;
@@ -626,7 +631,7 @@ PHP_RINIT_FUNCTION(mysql)
return FAILURE;
}
#endif
- MySG(default_link)=-1;
+ MySG(default_link) = NULL;
MySG(num_links) = MySG(num_persistent);
/* Reset connect error/errno on every request */
MySG(connect_error) = NULL;
@@ -637,10 +642,11 @@ PHP_RINIT_FUNCTION(mysql)
}
/* }}} */
-
#if defined(A0) && defined(MYSQL_USE_MYSQLND)
-static int php_mysql_persistent_helper(zend_rsrc_list_entry *le TSRMLS_DC)
+static int php_mysql_persistent_helper(zval *el;zend_rsrc_list_entry *le TSRMLS_DC)
{
+ //???
+ //zend_rsrc_list_entry *le = (zend_rsrc_list_entry*)Z_PTR_P(el);
if (le->type == le_plink) {
mysqlnd_end_psession(((php_mysql_conn *) le->ptr)->conn);
}
@@ -719,17 +725,19 @@ PHP_MINFO_FUNCTION(mysql)
static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
{
- char *user=NULL, *passwd=NULL, *host_and_port=NULL, *socket=NULL, *tmp=NULL, *host=NULL;
- int user_len = 0, passwd_len = 0, host_len = 0;
- char *hashed_details=NULL;
- int hashed_details_length, port = MYSQL_PORT;
+ char *user = NULL, *passwd = NULL;
+ char *host_and_port = NULL, *socket = NULL;
+ char *tmp = NULL, *host = NULL;
+ int user_len = 0, passwd_len = 0, host_len = 0;
+ int port = MYSQL_PORT;
long client_flags = 0;
- php_mysql_conn *mysql=NULL;
+ php_mysql_conn *mysql = NULL;
#if MYSQL_VERSION_ID <= 32230
void (*handler) (int);
#endif
- zend_bool free_host=0, new_link=0;
long connect_timeout;
+ zend_string *hashed_details = NULL;
+ zend_bool free_host = 0, new_link = 0;
php_error_docref(NULL TSRMLS_CC,
E_DEPRECATED,
@@ -754,10 +762,10 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
MySG(default_port) = MYSQL_PORT;
if ((serv_ptr = getservbyname("mysql", "tcp"))) {
- MySG(default_port) = (uint) ntohs((ushort) serv_ptr->s_port);
+ MySG(default_port) = (uint)ntohs((ushort)serv_ptr->s_port);
}
if ((env = getenv("MYSQL_TCP_PORT"))) {
- MySG(default_port) = (uint) atoi(env);
+ MySG(default_port) = (uint)atoi(env);
}
#else
MySG(default_port) = MYSQL_PORT;
@@ -768,9 +776,9 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
if (ZEND_NUM_ARGS()>0) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "SQL safe mode in effect - ignoring host/user/password information");
}
- host_and_port=passwd=NULL;
- user=php_get_current_user(TSRMLS_C);
- hashed_details_length = spprintf(&hashed_details, 0, "mysql__%s_", user);
+ user = php_get_current_user(TSRMLS_C);
+ hashed_details = STR_ALLOC(sizeof("mysql___") + strlen(user) - 1, 0);
+ snprintf(hashed_details->val, hashed_details->len + 1, "mysql__%s_", user);
client_flags = CLIENT_INTERACTIVE;
} else {
/* mysql_pconnect does not support new_link parameter */
@@ -814,13 +822,15 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
#ifdef CLIENT_MULTI_STATEMENTS
client_flags &= ~CLIENT_MULTI_STATEMENTS; /* don't allow multi_queries via connect parameter */
#endif
- hashed_details_length = spprintf(&hashed_details, 0, "mysql_%s_%s_%s_%ld", SAFE_STRING(host_and_port), SAFE_STRING(user), SAFE_STRING(passwd), client_flags);
+ hashed_details = STR_ALLOC(sizeof("mysql____") + (host_and_port? strlen(host_and_port) : 0)
+ + (user? strlen(user) : 0) + (passwd? strlen(passwd) : 0) + MAX_LENGTH_OF_LONG - 1, 0);
+ hashed_details->len = snprintf(hashed_details->val, hashed_details->len + 1, "mysql_%s_%s_%s_%ld", SAFE_STRING(host_and_port), SAFE_STRING(user), SAFE_STRING(passwd), client_flags);
}
/* We cannot use mysql_port anymore in windows, need to use
* mysql_real_connect() to set the port.
*/
- if (host_and_port && (tmp=strchr(host_and_port, ':'))) {
+ if (host_and_port && (tmp = strchr(host_and_port, ':'))) {
host = estrndup(host_and_port, tmp-host_and_port);
free_host = 1;
tmp++;
@@ -843,31 +853,35 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
#endif
if (!MySG(allow_persistent)) {
- persistent=0;
+ persistent = 0;
}
+
if (persistent) {
- zend_rsrc_list_entry *le;
+ zend_resource *le;
+ zend_string *phashed;
/* try to find if we already have this link in our persistent list */
- if (zend_hash_find(&EG(persistent_list), hashed_details, hashed_details_length+1, (void **) &le)==FAILURE) { /* we don't */
- zend_rsrc_list_entry new_le;
+ if ((le = zend_hash_find_ptr(&EG(persistent_list), hashed_details)) == NULL) { /* we don't */
+ zend_resource new_le;
if (MySG(max_links) != -1 && MySG(num_links) >= MySG(max_links)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too many open links (%ld)", MySG(num_links));
- efree(hashed_details);
+ STR_RELEASE(hashed_details);
MYSQL_DO_CONNECT_RETURN_FALSE();
}
+
if (MySG(max_persistent) != -1 && MySG(num_persistent) >= MySG(max_persistent)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too many open persistent links (%ld)", MySG(num_persistent));
- efree(hashed_details);
+ STR_RELEASE(hashed_details);
MYSQL_DO_CONNECT_RETURN_FALSE();
}
/* create the link */
- mysql = (php_mysql_conn *) malloc(sizeof(php_mysql_conn));
+ mysql = (php_mysql_conn *)malloc(sizeof(php_mysql_conn));
if (!mysql) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Out of memory while allocating memory for a persistent link");
+ php_error_docref(NULL TSRMLS_CC, E_ERROR,
+ "Out of memory while allocating memory for a persistent link");
}
- mysql->active_result_id = 0;
+ mysql->active_result_res = NULL;
#ifdef CLIENT_MULTI_STATEMENTS
mysql->multi_query = client_flags & CLIENT_MULTI_STATEMENTS? 1:0;
#else
@@ -893,33 +907,37 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
if (MySG(connect_error) != NULL) {
efree(MySG(connect_error));
}
+
MySG(connect_error) = estrdup(mysql_error(mysql->conn));
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", MySG(connect_error));
#if defined(HAVE_MYSQL_ERRNO)
MySG(connect_errno) = mysql_errno(mysql->conn);
#endif
free(mysql);
- efree(hashed_details);
+ STR_RELEASE(hashed_details);
MYSQL_DO_CONNECT_RETURN_FALSE();
}
mysql_options(mysql->conn, MYSQL_OPT_LOCAL_INFILE, (char *)&MySG(allow_local_infile));
/* hash it up */
- Z_TYPE(new_le) = le_plink;
+ new_le.type = le_plink;
new_le.ptr = mysql;
- if (zend_hash_update(&EG(persistent_list), hashed_details, hashed_details_length+1, (void *) &new_le, sizeof(zend_rsrc_list_entry), NULL)==FAILURE) {
+
+ /* avoid bogus memleak report */
+ phashed = STR_INIT(hashed_details->val, hashed_details->len, 1);
+ if (zend_hash_update_mem(&EG(persistent_list), phashed, &new_le, sizeof(zend_resource)) == NULL) {
free(mysql);
- efree(hashed_details);
+ STR_RELEASE(hashed_details);
MYSQL_DO_CONNECT_RETURN_FALSE();
}
MySG(num_persistent)++;
MySG(num_links)++;
} else { /* The link is in our list of persistent connections */
- if (Z_TYPE_P(le) != le_plink) {
+ if (le->type != le_plink) {
MYSQL_DO_CONNECT_RETURN_FALSE();
}
- mysql = (php_mysql_conn *) le->ptr;
- mysql->active_result_id = 0;
+ mysql = (php_mysql_conn *)le->ptr;
+ mysql->active_result_res = NULL;
#ifdef CLIENT_MULTI_STATEMENTS
mysql->multi_query = client_flags & CLIENT_MULTI_STATEMENTS? 1:0;
#else
@@ -938,8 +956,8 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
#endif
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Link to server lost, unable to reconnect");
- zend_hash_del(&EG(persistent_list), hashed_details, hashed_details_length+1);
- efree(hashed_details);
+ zend_hash_del(&EG(persistent_list), hashed_details);
+ STR_RELEASE(hashed_details);
MYSQL_DO_CONNECT_RETURN_FALSE();
}
mysql_options(mysql->conn, MYSQL_OPT_LOCAL_INFILE, (char *)&MySG(allow_local_infile));
@@ -952,43 +970,41 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
}
ZEND_REGISTER_RESOURCE(return_value, mysql, le_plink);
} else { /* non persistent */
- zend_rsrc_list_entry *index_ptr, new_index_ptr;
+ zend_resource *index_ptr, new_index_ptr;
/* first we check the hash for the hashed_details key. if it exists,
* it should point us to the right offset where the actual mysql link sits.
* if it doesn't, open a new mysql link, add it to the resource list,
* and add a pointer to it with hashed_details as the key.
*/
- if (!new_link && zend_hash_find(&EG(regular_list), hashed_details, hashed_details_length+1,(void **) &index_ptr)==SUCCESS) {
- int type;
- long link;
- void *ptr;
+ if (!new_link && (index_ptr = zend_hash_find_ptr(&EG(regular_list), hashed_details))) {
+ zend_resource *link;
- if (Z_TYPE_P(index_ptr) != le_index_ptr) {
+ if (index_ptr->type != le_index_ptr) {
MYSQL_DO_CONNECT_RETURN_FALSE();
}
- link = (long) index_ptr->ptr;
- ptr = zend_list_find(link,&type); /* check if the link is still there */
- if (ptr && (type==le_link || type==le_plink)) {
- zend_list_addref(link);
- Z_LVAL_P(return_value) = link;
+
+ link = (zend_resource *)index_ptr->ptr;
+ if (link && (link->type == le_link || link->type == le_plink)) {
+ link->gc.refcount++;
+ ZVAL_RES(return_value, link);
php_mysql_set_default_link(link TSRMLS_CC);
- Z_TYPE_P(return_value) = IS_RESOURCE;
- efree(hashed_details);
+ STR_RELEASE(hashed_details);
MYSQL_DO_CONNECT_CLEANUP();
return;
} else {
- zend_hash_del(&EG(regular_list), hashed_details, hashed_details_length+1);
+ zend_hash_del(&EG(regular_list), hashed_details);
}
}
+
if (MySG(max_links) != -1 && MySG(num_links) >= MySG(max_links)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too many open links (%ld)", MySG(num_links));
- efree(hashed_details);
+ STR_RELEASE(hashed_details);
MYSQL_DO_CONNECT_RETURN_FALSE();
}
mysql = (php_mysql_conn *) emalloc(sizeof(php_mysql_conn));
- mysql->active_result_id = 0;
+ mysql->active_result_res = NULL;
#ifdef CLIENT_MULTI_STATEMENTS
mysql->multi_query = 1;
#endif
@@ -1001,7 +1017,7 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
if (!mysql->conn) {
MySG(connect_error) = estrdup("OOM");
php_error_docref(NULL TSRMLS_CC, E_WARNING, "OOM");
- efree(hashed_details);
+ STR_RELEASE(hashed_details);
efree(mysql);
MYSQL_DO_CONNECT_RETURN_FALSE();
}
@@ -1029,7 +1045,7 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
#ifdef MYSQL_USE_MYSQLND
mysqlnd_close(mysql->conn, MYSQLND_CLOSE_DISCONNECTED);
#endif
- efree(hashed_details);
+ STR_RELEASE(hashed_details);
efree(mysql);
MYSQL_DO_CONNECT_RETURN_FALSE();
}
@@ -1039,27 +1055,28 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
ZEND_REGISTER_RESOURCE(return_value, mysql, le_link);
/* add it to the hash */
- new_index_ptr.ptr = (void *) Z_LVAL_P(return_value);
- Z_TYPE(new_index_ptr) = le_index_ptr;
- if (zend_hash_update(&EG(regular_list), hashed_details, hashed_details_length+1,(void *) &new_index_ptr, sizeof(zend_rsrc_list_entry), NULL)==FAILURE) {
- efree(hashed_details);
+ new_index_ptr.ptr = Z_RES_P(return_value);
+ new_index_ptr.type = le_index_ptr;
+
+ if (zend_hash_update_mem(&EG(regular_list), hashed_details, &new_index_ptr, sizeof(zend_resource)) == NULL) {
+ STR_RELEASE(hashed_details);
MYSQL_DO_CONNECT_RETURN_FALSE();
}
MySG(num_links)++;
}
- efree(hashed_details);
- php_mysql_set_default_link(Z_LVAL_P(return_value) TSRMLS_CC);
+ STR_RELEASE(hashed_details);
+ php_mysql_set_default_link(Z_RES_P(return_value) TSRMLS_CC);
MYSQL_DO_CONNECT_CLEANUP();
}
/* }}} */
/* {{{ php_mysql_get_default_link
*/
-static int php_mysql_get_default_link(INTERNAL_FUNCTION_PARAMETERS)
+static zend_resource *php_mysql_get_default_link(INTERNAL_FUNCTION_PARAMETERS)
{
- if (MySG(default_link)==-1) { /* no link opened yet, implicitly open one */
- ht = 0;
+ if (MySG(default_link) == NULL) { /* no link opened yet, implicitly open one */
+ ZEND_NUM_ARGS() = 0;
php_mysql_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
return MySG(default_link);
@@ -1086,8 +1103,8 @@ PHP_FUNCTION(mysql_pconnect)
Close a MySQL connection */
PHP_FUNCTION(mysql_close)
{
- int resource_id;
- zval *mysql_link=NULL;
+ zend_resource *res;
+ zval *mysql_link = NULL;
php_mysql_conn *mysql;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &mysql_link) == FAILURE) {
@@ -1095,29 +1112,28 @@ PHP_FUNCTION(mysql_close)
}
if (mysql_link) {
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, -1, "MySQL-Link", le_link, le_plink);
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
} else {
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, NULL, MySG(default_link), "MySQL-Link", le_link, le_plink);
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, NULL, MySG(default_link)? MySG(default_link)->handle : -1, "MySQL-Link", le_link, le_plink);
}
- resource_id = mysql_link ? Z_RESVAL_P(mysql_link) : MySG(default_link);
+ res = mysql_link ? Z_RES_P(mysql_link) : MySG(default_link);
PHPMY_UNBUFFERED_QUERY_CHECK();
+ if (res) {
#ifdef MYSQL_USE_MYSQLND
- {
- int tmp;
- if ((mysql = zend_list_find(resource_id, &tmp)) && tmp == le_plink) {
+ if (res->type == le_plink) {
mysqlnd_end_psession(mysql->conn);
}
- }
#endif
- zend_list_delete(resource_id);
-
- if (!mysql_link
- || (mysql_link && Z_RESVAL_P(mysql_link)==MySG(default_link))) {
- MySG(default_link) = -1;
- if (mysql_link) {
- /* on an explicit close of the default connection it had a refcount of 2 so we need one more call */
- zend_list_delete(resource_id);
+ if (!mysql_link) {
+ --res->gc.refcount;
+ MySG(default_link) = NULL;
+ } else if (mysql_link && Z_RES_P(mysql_link) == MySG(default_link)) {
+ --res->gc.refcount;
+ MySG(default_link) = NULL;
+ zend_list_close(res);
+ } else {
+ zend_list_close(res);
}
}
@@ -1131,21 +1147,21 @@ PHP_FUNCTION(mysql_select_db)
{
char *db;
int db_len;
- zval *mysql_link = NULL;
- int id = -1;
php_mysql_conn *mysql;
+ zval *mysql_link = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|r", &db, &db_len, &mysql_link) == FAILURE) {
return;
}
if (!mysql_link) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
+ zend_resource *res = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(res);
+ mysql = (php_mysql_conn*)res->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
-
if (php_mysql_select_db(mysql, db TSRMLS_CC)) {
RETURN_TRUE;
} else {
@@ -1164,7 +1180,7 @@ PHP_FUNCTION(mysql_get_client_info)
return;
}
- RETURN_STRING((char *)mysql_get_client_info(),1);
+ RETURN_STRING((char *)mysql_get_client_info());
}
/* }}} */
@@ -1173,7 +1189,6 @@ PHP_FUNCTION(mysql_get_client_info)
PHP_FUNCTION(mysql_get_host_info)
{
zval *mysql_link = NULL;
- int id = -1;
php_mysql_conn *mysql;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &mysql_link) == FAILURE) {
@@ -1181,13 +1196,14 @@ PHP_FUNCTION(mysql_get_host_info)
}
if (!mysql_link) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
+ zend_resource *res = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(res);
+ mysql = (php_mysql_conn*)res->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
-
- RETURN_STRING((char *)mysql_get_host_info(mysql->conn),1);
+ RETURN_STRING((char *)mysql_get_host_info(mysql->conn));
}
/* }}} */
@@ -1196,7 +1212,6 @@ PHP_FUNCTION(mysql_get_host_info)
PHP_FUNCTION(mysql_get_proto_info)
{
zval *mysql_link = NULL;
- int id = -1;
php_mysql_conn *mysql;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &mysql_link) == FAILURE) {
@@ -1204,12 +1219,13 @@ PHP_FUNCTION(mysql_get_proto_info)
}
if (!mysql_link) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
+ zend_resource *res = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(res);
+ mysql = (php_mysql_conn*)res->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
-
RETURN_LONG(mysql_get_proto_info(mysql->conn));
}
/* }}} */
@@ -1219,7 +1235,6 @@ PHP_FUNCTION(mysql_get_proto_info)
PHP_FUNCTION(mysql_get_server_info)
{
zval *mysql_link = NULL;
- int id = -1;
php_mysql_conn *mysql;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &mysql_link) == FAILURE) {
@@ -1227,13 +1242,14 @@ PHP_FUNCTION(mysql_get_server_info)
}
if (!mysql_link) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
+ zend_resource *res = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(res);
+ mysql = (php_mysql_conn*)res->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
-
- RETURN_STRING((char *)mysql_get_server_info(mysql->conn),1);
+ RETURN_STRING((char *)mysql_get_server_info(mysql->conn));
}
/* }}} */
@@ -1241,24 +1257,24 @@ PHP_FUNCTION(mysql_get_server_info)
Returns a string containing information about the most recent query */
PHP_FUNCTION(mysql_info)
{
- zval *mysql_link = NULL;
- int id = -1;
char *str;
+ zval *mysql_link = NULL;
php_mysql_conn *mysql;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &mysql_link) == FAILURE) {
return;
}
-
- if (ZEND_NUM_ARGS() == 0) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
+
+ if (!mysql_link) {
+ zend_resource *res = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(res);
+ mysql = (php_mysql_conn*)res->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
-
if ((str = (char *)mysql_info(mysql->conn))) {
- RETURN_STRING(str,1);
+ RETURN_STRING(str);
} else {
RETURN_FALSE;
}
@@ -1270,18 +1286,19 @@ PHP_FUNCTION(mysql_info)
PHP_FUNCTION(mysql_thread_id)
{
zval *mysql_link = NULL;
- int id = -1;
php_mysql_conn *mysql;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &mysql_link) == FAILURE) {
return;
}
- if (ZEND_NUM_ARGS() == 0) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
+ if (!mysql_link) {
+ zend_resource *res = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(res);
+ mysql = (php_mysql_conn*)res->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
RETURN_LONG((long) mysql_thread_id(mysql->conn));
}
@@ -1291,9 +1308,8 @@ PHP_FUNCTION(mysql_thread_id)
Returns a string containing status information */
PHP_FUNCTION(mysql_stat)
{
- zval *mysql_link = NULL;
- int id = -1;
php_mysql_conn *mysql;
+ zval *mysql_link = NULL;
char *stat;
#ifdef MYSQL_USE_MYSQLND
uint stat_len;
@@ -1303,19 +1319,22 @@ PHP_FUNCTION(mysql_stat)
return;
}
- if (ZEND_NUM_ARGS() == 0) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
+ if (!mysql_link) {
+ zend_resource *res = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(res);
+ mysql = (php_mysql_conn*)res->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
PHPMY_UNBUFFERED_QUERY_CHECK();
#ifndef MYSQL_USE_MYSQLND
if ((stat = (char *)mysql_stat(mysql->conn))) {
- RETURN_STRING(stat, 1);
+ RETURN_STRING(stat);
#else
if (mysqlnd_stat(mysql->conn, &stat, &stat_len) == PASS) {
- RETURN_STRINGL(stat, stat_len, 0);
+ //???? memleak
+ RETURN_STRINGL(stat, stat_len);
#endif
} else {
RETURN_FALSE;
@@ -1327,21 +1346,22 @@ PHP_FUNCTION(mysql_stat)
Returns the default character set for the current connection */
PHP_FUNCTION(mysql_client_encoding)
{
- zval *mysql_link = NULL;
- int id = -1;
php_mysql_conn *mysql;
+ zval *mysql_link = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &mysql_link) == FAILURE) {
return;
}
- if (ZEND_NUM_ARGS() == 0) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
+ if (!mysql_link) {
+ zend_resource *res = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(res);
+ mysql = (php_mysql_conn*)res->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
- RETURN_STRING((char *)mysql_character_set_name(mysql->conn), 1);
+ RETURN_STRING((char *)mysql_character_set_name(mysql->conn));
}
/* }}} */
#endif
@@ -1351,22 +1371,23 @@ PHP_FUNCTION(mysql_client_encoding)
sets client character set */
PHP_FUNCTION(mysql_set_charset)
{
- zval *mysql_link = NULL;
char *csname;
- int id = -1, csname_len;
+ int csname_len;
php_mysql_conn *mysql;
+ zval *mysql_link = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|r", &csname, &csname_len, &mysql_link) == FAILURE) {
return;
}
- if (ZEND_NUM_ARGS() == 1) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
+ if (!mysql_link) {
+ zend_resource *res = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(res);
+ mysql = (php_mysql_conn*)res->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
-
if (!mysql_set_character_set(mysql->conn, csname)) {
RETURN_TRUE;
} else {
@@ -1384,21 +1405,21 @@ PHP_FUNCTION(mysql_create_db)
{
char *db;
int db_len;
- zval *mysql_link = NULL;
- int id = -1;
php_mysql_conn *mysql;
+ zval *mysql_link = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|r", &db, &db_len, &mysql_link) == FAILURE) {
return;
}
if (!mysql_link) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
+ zend_resource *res = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(res);
+ mysql = (php_mysql_conn*)res->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
-
PHPMY_UNBUFFERED_QUERY_CHECK();
if (mysql_create_db(mysql->conn, db)==0) {
@@ -1415,21 +1436,21 @@ PHP_FUNCTION(mysql_drop_db)
{
char *db;
int db_len;
- zval *mysql_link = NULL;
- int id = -1;
php_mysql_conn *mysql;
+ zval *mysql_link = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|r", &db, &db_len, &mysql_link) == FAILURE) {
return;
}
if (!mysql_link) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
+ zend_resource *res = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(res);
+ mysql = (php_mysql_conn*)res->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
-
if (mysql_drop_db(mysql->conn, db)==0) {
RETURN_TRUE;
} else {
@@ -1442,13 +1463,10 @@ PHP_FUNCTION(mysql_drop_db)
/* {{{ php_mysql_do_query_general
*/
-static void php_mysql_do_query_general(char *query, int query_len, zval *mysql_link, int link_id, char *db, int use_store, zval *return_value TSRMLS_DC)
+static void php_mysql_do_query_general(php_mysql_conn *mysql, char *query, int query_len, char *db, int use_store, zval *return_value TSRMLS_DC)
{
- php_mysql_conn *mysql;
MYSQL_RES *mysql_result;
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, link_id, "MySQL-Link", le_link, le_plink);
-
if (db) {
if (!php_mysql_select_db(mysql, db TSRMLS_CC)) {
RETURN_FALSE;
@@ -1466,7 +1484,7 @@ static void php_mysql_do_query_general(char *query, int query_len, zval *mysql_l
MYSQL_ROW row;
char *newquery;
- int newql = spprintf (&newquery, 0, "EXPLAIN %s", query);
+ int newql = spprintf(&newquery, 0, "EXPLAIN %s", query);
mysql_real_query(mysql->conn, newquery, newql);
efree (newquery);
if (mysql_errno(mysql->conn)) {
@@ -1511,9 +1529,9 @@ static void php_mysql_do_query_general(char *query, int query_len, zval *mysql_l
}
#endif
if(use_store == MYSQL_USE_RESULT) {
- mysql_result=mysql_use_result(mysql->conn);
+ mysql_result = mysql_use_result(mysql->conn);
} else {
- mysql_result=mysql_store_result(mysql->conn);
+ mysql_result = mysql_store_result(mysql->conn);
}
if (!mysql_result) {
if (PHP_MYSQL_VALID_RESULT(mysql->conn)) { /* query should have returned rows */
@@ -1526,7 +1544,7 @@ static void php_mysql_do_query_general(char *query, int query_len, zval *mysql_l
MySG(result_allocated)++;
ZEND_REGISTER_RESOURCE(return_value, mysql_result, le_result);
if (use_store == MYSQL_USE_RESULT) {
- mysql->active_result_id = Z_LVAL_P(return_value);
+ mysql->active_result_res = Z_RES_P(return_value);
}
}
/* }}} */
@@ -1538,18 +1556,21 @@ static void php_mysql_do_query(INTERNAL_FUNCTION_PARAMETERS, int use_store)
char *query;
int query_len;
zval *mysql_link = NULL;
- int id = -1;
+ php_mysql_conn *mysql;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|r", &query, &query_len, &mysql_link) == FAILURE) {
return;
}
if (!mysql_link) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
+ zend_resource *res = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(res);
+ mysql = (php_mysql_conn*)res->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
- php_mysql_do_query_general(query, query_len, mysql_link, id, NULL, use_store, return_value TSRMLS_CC);
+ php_mysql_do_query_general(mysql, query, query_len, NULL, use_store, return_value TSRMLS_CC);
}
/* }}} */
@@ -1561,7 +1582,6 @@ PHP_FUNCTION(mysql_query)
}
/* }}} */
-
/* {{{ proto resource mysql_unbuffered_query(string query [, int link_identifier])
Sends an SQL query to MySQL, without fetching and buffering the result rows */
PHP_FUNCTION(mysql_unbuffered_query)
@@ -1570,75 +1590,75 @@ PHP_FUNCTION(mysql_unbuffered_query)
}
/* }}} */
-
/* {{{ proto resource mysql_db_query(string database_name, string query [, int link_identifier])
Sends an SQL query to MySQL */
PHP_FUNCTION(mysql_db_query)
{
char *db, *query;
int db_len, query_len;
+ php_mysql_conn *mysql;
zval *mysql_link = NULL;
- int id = -1;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|r", &db, &db_len, &query, &query_len, &mysql_link) == FAILURE) {
return;
}
if (!mysql_link) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
+ zend_resource *res = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(res);
+ mysql = (php_mysql_conn*)res->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "This function is deprecated; use mysql_query() instead");
- php_mysql_do_query_general(query, query_len, mysql_link, id, db, MYSQL_STORE_RESULT, return_value TSRMLS_CC);
+ php_mysql_do_query_general(mysql, query, query_len, db, MYSQL_STORE_RESULT, return_value TSRMLS_CC);
}
/* }}} */
-
/* {{{ proto resource mysql_list_dbs([int link_identifier])
List databases available on a MySQL server */
PHP_FUNCTION(mysql_list_dbs)
{
- zval *mysql_link = NULL;
- int id = -1;
php_mysql_conn *mysql;
MYSQL_RES *mysql_result;
+ zval *mysql_link = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &mysql_link) == FAILURE) {
return;
}
if (!mysql_link) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
+ zend_resource *res = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(res);
+ mysql = (php_mysql_conn*)res->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
- php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "This function is deprecated; use mysql_query() with SHOW DATABASES instead");
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
+ php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "This function is deprecated; use mysql_query() with SHOW DATABASES instead");
PHPMY_UNBUFFERED_QUERY_CHECK();
-
- if ((mysql_result=mysql_list_dbs(mysql->conn, NULL))==NULL) {
+ if ((mysql_result = mysql_list_dbs(mysql->conn, NULL))==NULL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to save MySQL query result");
RETURN_FALSE;
}
+
MySG(result_allocated)++;
ZEND_REGISTER_RESOURCE(return_value, mysql_result, le_result);
}
/* }}} */
-
/* {{{ proto resource mysql_list_tables(string database_name [, int link_identifier])
List tables in a MySQL database */
PHP_FUNCTION(mysql_list_tables)
{
char *db;
int db_len;
- zval *mysql_link = NULL;
- int id = -1;
php_mysql_conn *mysql;
+ zval *mysql_link = NULL;
MYSQL_RES *mysql_result;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|r", &db, &db_len, &mysql_link) == FAILURE) {
@@ -1646,19 +1666,20 @@ PHP_FUNCTION(mysql_list_tables)
}
if (!mysql_link) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
+ zend_resource *res = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(res);
+ mysql = (php_mysql_conn*)res->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
-
if (!php_mysql_select_db(mysql, db TSRMLS_CC)) {
RETURN_FALSE;
}
PHPMY_UNBUFFERED_QUERY_CHECK();
- if ((mysql_result=mysql_list_tables(mysql->conn, NULL))==NULL) {
+ if ((mysql_result = mysql_list_tables(mysql->conn, NULL))==NULL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to save MySQL query result");
RETURN_FALSE;
}
@@ -1667,7 +1688,6 @@ PHP_FUNCTION(mysql_list_tables)
}
/* }}} */
-
/* {{{ proto resource mysql_list_fields(string database_name, string table_name [, int link_identifier])
List MySQL result fields */
PHP_FUNCTION(mysql_list_fields)
@@ -1675,7 +1695,6 @@ PHP_FUNCTION(mysql_list_fields)
char *db, *table;
int db_len, table_len;
zval *mysql_link = NULL;
- int id = -1;
php_mysql_conn *mysql;
MYSQL_RES *mysql_result;
@@ -1684,12 +1703,13 @@ PHP_FUNCTION(mysql_list_fields)
}
if (!mysql_link) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
+ zend_resource *res = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(res);
+ mysql = (php_mysql_conn*)res->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
-
if (!php_mysql_select_db(mysql, db TSRMLS_CC)) {
RETURN_FALSE;
}
@@ -1709,22 +1729,22 @@ PHP_FUNCTION(mysql_list_fields)
Returns a result set describing the current server threads */
PHP_FUNCTION(mysql_list_processes)
{
- zval *mysql_link = NULL;
- int id = -1;
php_mysql_conn *mysql;
+ zval *mysql_link = NULL;
MYSQL_RES *mysql_result;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &mysql_link) == FAILURE) {
return;
}
- if (ZEND_NUM_ARGS() == 0) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
+ if (!mysql_link) {
+ zend_resource *res = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(res);
+ mysql = (php_mysql_conn*)res->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
-
PHPMY_UNBUFFERED_QUERY_CHECK();
mysql_result = mysql_list_processes(mysql->conn);
@@ -1738,101 +1758,95 @@ PHP_FUNCTION(mysql_list_processes)
}
/* }}} */
-
/* {{{ proto string mysql_error([int link_identifier])
Returns the text of the error message from previous MySQL operation */
PHP_FUNCTION(mysql_error)
{
- zval *mysql_link = NULL;
- int id = -1;
php_mysql_conn *mysql;
+ zval *mysql_link = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &mysql_link) == FAILURE) {
return;
}
if (!mysql_link) {
- id = MySG(default_link);
- if (id==-1) {
- if (MySG(connect_error)!=NULL){
- RETURN_STRING(MySG(connect_error),1);
+ if (MySG(default_link) == NULL) {
+ if (MySG(connect_error) != NULL){
+ RETURN_STRING(MySG(connect_error));
} else {
RETURN_FALSE;
}
}
+ mysql = (php_mysql_conn*)MySG(default_link)->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
-
- RETURN_STRING((char *)mysql_error(mysql->conn), 1);
+ RETURN_STRING((char *)mysql_error(mysql->conn));
}
/* }}} */
-
/* {{{ proto int mysql_errno([int link_identifier])
Returns the number of the error message from previous MySQL operation */
#ifdef HAVE_MYSQL_ERRNO
PHP_FUNCTION(mysql_errno)
{
- zval *mysql_link = NULL;
- int id = -1;
php_mysql_conn *mysql;
+ zval *mysql_link = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &mysql_link) == FAILURE) {
return;
}
if (!mysql_link) {
- id = MySG(default_link);
- if (id==-1) {
- if (MySG(connect_errno)!=0){
+ if (MySG(default_link) == NULL) {
+ if (MySG(connect_error) != NULL){
RETURN_LONG(MySG(connect_errno));
} else {
RETURN_FALSE;
}
}
+ mysql = (php_mysql_conn*)MySG(default_link)->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
-
RETURN_LONG(mysql_errno(mysql->conn));
}
#endif
/* }}} */
-
/* {{{ proto int mysql_affected_rows([int link_identifier])
Gets number of affected rows in previous MySQL operation */
PHP_FUNCTION(mysql_affected_rows)
{
- zval *mysql_link = NULL;
- int id = -1;
php_mysql_conn *mysql;
+ zval *mysql_link = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &mysql_link) == FAILURE) {
return;
}
if (!mysql_link) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
+ zend_resource *res = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(res);
+ mysql = (php_mysql_conn*)res->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
-
/* conversion from int64 to long happing here */
- Z_LVAL_P(return_value) = (long) mysql_affected_rows(mysql->conn);
- Z_TYPE_P(return_value) = IS_LONG;
+ RETURN_LONG((long)mysql_affected_rows(mysql->conn));
}
/* }}} */
-
/* {{{ proto string mysql_escape_string(string to_be_escaped)
Escape string for mysql query */
PHP_FUNCTION(mysql_escape_string)
{
char *str;
int str_len;
+ zend_string *escaped_str;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
return;
@@ -1842,12 +1856,11 @@ PHP_FUNCTION(mysql_escape_string)
* we don't realloc() down to the real size since it'd most probably not
* be worth it
*/
-
- Z_STRVAL_P(return_value) = (char *) safe_emalloc(str_len, 2, 1);
- Z_STRLEN_P(return_value) = mysql_escape_string(Z_STRVAL_P(return_value), str, str_len);
- Z_TYPE_P(return_value) = IS_STRING;
+ escaped_str = STR_ALLOC(str_len * 2, 0);
+ escaped_str->len = mysql_escape_string(escaped_str->val, str, str_len);
php_error_docref("function.mysql-real-escape-string" TSRMLS_CC, E_DEPRECATED, "This function is deprecated; use mysql_real_escape_string() instead.");
+ RETURN_STR(escaped_str);
}
/* }}} */
@@ -1855,29 +1868,32 @@ PHP_FUNCTION(mysql_escape_string)
Escape special characters in a string for use in a SQL statement, taking into account the current charset of the connection */
PHP_FUNCTION(mysql_real_escape_string)
{
- zval *mysql_link = NULL;
char *str;
- char *new_str;
- int id = -1, str_len, new_str_len;
+ int str_len;
+ zend_string *new_str;
php_mysql_conn *mysql;
-
+ zval *mysql_link = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|r", &str, &str_len, &mysql_link) == FAILURE) {
return;
}
- if (ZEND_NUM_ARGS() == 1) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
+ if (!mysql_link) {
+ zend_resource *res = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(res);
+ mysql = (php_mysql_conn*)res->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
-
- new_str = safe_emalloc(str_len, 2, 1);
- new_str_len = mysql_real_escape_string(mysql->conn, new_str, str, str_len);
- new_str = erealloc(new_str, new_str_len + 1);
+ /* assume worst case situation, which is 2x of the original string.
+ * we don't realloc() down to the real size since it'd most probably not
+ * be worth it
+ */
+ new_str = STR_ALLOC(str_len * 2, 0);
+ new_str->len = mysql_real_escape_string(mysql->conn, new_str->val, str, str_len);
- RETURN_STRINGL(new_str, new_str_len, 0);
+ RETURN_STR(new_str);
}
/* }}} */
@@ -1885,28 +1901,26 @@ PHP_FUNCTION(mysql_real_escape_string)
Gets the ID generated from the previous INSERT operation */
PHP_FUNCTION(mysql_insert_id)
{
- zval *mysql_link = NULL;
- int id = -1;
php_mysql_conn *mysql;
+ zval *mysql_link = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &mysql_link) == FAILURE) {
return;
}
if (!mysql_link) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
+ zend_resource *res = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(res);
+ mysql = (php_mysql_conn*)res->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
}
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
-
/* conversion from int64 to long happing here */
- Z_LVAL_P(return_value) = (long) mysql_insert_id(mysql->conn);
- Z_TYPE_P(return_value) = IS_LONG;
+ RETURN_LONG((long)mysql_insert_id(mysql->conn));
}
/* }}} */
-
/* {{{ proto mixed mysql_result(resource result, int row [, mixed field])
Gets result data */
PHP_FUNCTION(mysql_result)
@@ -1929,30 +1943,30 @@ Q: String or long first?
return;
}
- ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, &result, -1, "MySQL result", le_result);
+ ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, result, -1, "MySQL result", le_result);
- if (row<0 || row>=(int)mysql_num_rows(mysql_result)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to jump to row %ld on MySQL result index %ld", row, Z_LVAL_P(result));
+ if (row < 0 || row >= (int)mysql_num_rows(mysql_result)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to jump to row %ld on MySQL result index %ld", row, Z_RES_P(result)->handle);
RETURN_FALSE;
}
mysql_data_seek(mysql_result, row);
if (field) {
- switch(Z_TYPE_P(field)) {
+ switch (Z_TYPE_P(field)) {
case IS_STRING: {
- int i=0;
+ int i = 0;
const MYSQL_FIELD *tmp_field;
char *table_name, *field_name, *tmp;
- if ((tmp=strchr(Z_STRVAL_P(field), '.'))) {
+ if ((tmp = strchr(Z_STRVAL_P(field), '.'))) {
table_name = estrndup(Z_STRVAL_P(field), tmp-Z_STRVAL_P(field));
- field_name = estrdup(tmp+1);
+ field_name = estrdup(tmp + 1);
} else {
table_name = NULL;
field_name = estrndup(Z_STRVAL_P(field),Z_STRLEN_P(field));
}
mysql_field_seek(mysql_result, 0);
- while ((tmp_field=mysql_fetch_field(mysql_result))) {
+ while ((tmp_field = mysql_fetch_field(mysql_result))) {
if ((!table_name || !strcasecmp(tmp_field->table, table_name)) && !strcasecmp(tmp_field->name, field_name)) {
field_offset = i;
break;
@@ -1975,9 +1989,9 @@ Q: String or long first?
}
break;
default:
- convert_to_long_ex(&field);
+ convert_to_long_ex(field);
field_offset = Z_LVAL_P(field);
- if (field_offset<0 || field_offset>=(int)mysql_num_fields(mysql_result)) {
+ if (field_offset < 0 || field_offset >= (int)mysql_num_fields(mysql_result)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad column offset specified");
RETURN_FALSE;
}
@@ -1986,25 +2000,22 @@ Q: String or long first?
}
#ifndef MYSQL_USE_MYSQLND
- if ((sql_row=mysql_fetch_row(mysql_result))==NULL
- || (sql_row_lengths=mysql_fetch_lengths(mysql_result))==NULL) { /* shouldn't happen? */
+ if ((sql_row = mysql_fetch_row(mysql_result)) == NULL
+ || (sql_row_lengths=mysql_fetch_lengths(mysql_result)) == NULL) { /* shouldn't happen? */
RETURN_FALSE;
}
if (sql_row[field_offset]) {
- Z_TYPE_P(return_value) = IS_STRING;
-
#if PHP_API_VERSION < 20100412
if (PG(magic_quotes_runtime)) {
- Z_STRVAL_P(return_value) = php_addslashes(sql_row[field_offset], sql_row_lengths[field_offset],&Z_STRLEN_P(return_value), 0 TSRMLS_CC);
+ RETVAL_STR(php_addslashes(sql_row[field_offset], sql_row_lengths[field_offset], 0 TSRMLS_CC));
} else {
#endif
- Z_STRLEN_P(return_value) = sql_row_lengths[field_offset];
- Z_STRVAL_P(return_value) = (char *) safe_estrndup(sql_row[field_offset], Z_STRLEN_P(return_value));
+ RETVAL_STRINGL(sql_row[field_offset], sql_row_lengths[field_offset]);
#if PHP_API_VERSION < 20100412
}
#endif
} else {
- Z_TYPE_P(return_value) = IS_NULL;
+ RETURN_NULL();
}
#else
mysqlnd_result_fetch_field_data(mysql_result, field_offset, return_value);
@@ -2012,7 +2023,6 @@ Q: String or long first?
}
/* }}} */
-
/* {{{ proto int mysql_num_rows(resource result)
Gets number of rows in a result */
PHP_FUNCTION(mysql_num_rows)
@@ -2024,11 +2034,10 @@ PHP_FUNCTION(mysql_num_rows)
return;
}
- ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, &result, -1, "MySQL result", le_result);
+ ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, result, -1, "MySQL result", le_result);
/* conversion from int64 to long happing here */
- Z_LVAL_P(return_value) = (long) mysql_num_rows(mysql_result);
- Z_TYPE_P(return_value) = IS_LONG;
+ RETURN_LONG((long) mysql_num_rows(mysql_result));
}
/* }}} */
@@ -2043,10 +2052,9 @@ PHP_FUNCTION(mysql_num_fields)
return;
}
- ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, &result, -1, "MySQL result", le_result);
+ ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, result, -1, "MySQL result", le_result);
- Z_LVAL_P(return_value) = mysql_num_fields(mysql_result);
- Z_TYPE_P(return_value) = IS_LONG;
+ RETURN_LONG(mysql_num_fields(mysql_result));
}
/* }}} */
@@ -2055,7 +2063,7 @@ PHP_FUNCTION(mysql_num_fields)
static void php_mysql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type, int expected_args, int into_object)
{
MYSQL_RES *mysql_result;
- zval *res, *ctor_params = NULL;
+ zval *res, *ctor_params = NULL;
zend_class_entry *ce = NULL;
#ifndef MYSQL_USE_MYSQLND
int i;
@@ -2066,20 +2074,19 @@ static void php_mysql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type,
#ifdef ZEND_ENGINE_2
if (into_object) {
- char *class_name = NULL;
- int class_name_len = 0;
+ zend_string *class_name = NULL;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|sz", &res, &class_name, &class_name_len, &ctor_params) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|Sz", &res, &class_name, &ctor_params) == FAILURE) {
return;
}
if (ZEND_NUM_ARGS() < 2) {
ce = zend_standard_class_def;
} else {
- ce = zend_fetch_class(class_name, class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
+ ce = zend_fetch_class(class_name, ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
}
if (!ce) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not find class '%s'", class_name);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not find class '%s'", class_name->val);
return;
}
result_type = MYSQL_ASSOC;
@@ -2100,7 +2107,7 @@ static void php_mysql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type,
result_type = MYSQL_BOTH;
}
- ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, &res, -1, "MySQL result", le_result);
+ ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, res, -1, "MySQL result", le_result);
#ifndef MYSQL_USE_MYSQLND
if ((mysql_row = mysql_fetch_row(mysql_result)) == NULL ||
@@ -2116,29 +2123,26 @@ static void php_mysql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type,
mysql_field = mysql_fetch_field(mysql_result), i++)
{
if (mysql_row[i]) {
- zval *data;
-
- MAKE_STD_ZVAL(data);
+ zval data;
#if PHP_API_VERSION < 20100412
if (PG(magic_quotes_runtime)) {
- Z_TYPE_P(data) = IS_STRING;
- Z_STRVAL_P(data) = php_addslashes(mysql_row[i], mysql_row_lengths[i], &Z_STRLEN_P(data), 0 TSRMLS_CC);
+ ZVAL_STR(&data, php_addslashes(mysql_row[i], mysql_row_lengths[i], 0 TSRMLS_CC));
} else {
#endif
- ZVAL_STRINGL(data, mysql_row[i], mysql_row_lengths[i], 1);
+ ZVAL_STRINGL(&data, mysql_row[i], mysql_row_lengths[i]);
#if PHP_API_VERSION < 20100412
}
#endif
if (result_type & MYSQL_NUM) {
- add_index_zval(return_value, i, data);
+ add_index_zval(return_value, i, &data);
}
if (result_type & MYSQL_ASSOC) {
if (result_type & MYSQL_NUM) {
- Z_ADDREF_P(data);
+ Z_ADDREF_P(&data);
}
- add_assoc_zval(return_value, mysql_field->name, data);
+ add_assoc_zval(return_value, mysql_field->name, &data);
}
} else {
/* NULL value. */
@@ -2158,21 +2162,23 @@ static void php_mysql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type,
#ifdef ZEND_ENGINE_2
/* mysqlnd might return FALSE if no more rows */
if (into_object && Z_TYPE_P(return_value) != IS_BOOL) {
- zval dataset = *return_value;
+ zval dataset;
zend_fcall_info fci;
zend_fcall_info_cache fcc;
- zval *retval_ptr;
+ zval retval;
+ ZVAL_COPY_VALUE(&dataset, return_value);
object_and_properties_init(return_value, ce, NULL);
- zend_merge_properties(return_value, Z_ARRVAL(dataset), 1 TSRMLS_CC);
+ zend_merge_properties(return_value, Z_ARRVAL(dataset), 0 TSRMLS_CC);
+ zval_dtor(&dataset);
if (ce->constructor) {
fci.size = sizeof(fci);
fci.function_table = &ce->function_table;
- fci.function_name = NULL;
+ ZVAL_UNDEF(&fci.function_name);
fci.symbol_table = NULL;
fci.object_ptr = return_value;
- fci.retval_ptr_ptr = &retval_ptr;
+ fci.retval = &retval;
if (ctor_params && Z_TYPE_P(ctor_params) != IS_NULL) {
if (Z_TYPE_P(ctor_params) == IS_ARRAY) {
HashTable *htl = Z_ARRVAL_P(ctor_params);
@@ -2180,11 +2186,11 @@ static void php_mysql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type,
Bucket *p;
fci.param_count = 0;
- fci.params = safe_emalloc(sizeof(zval*), htl->nNumOfElements, 0);
+ fci.params = safe_emalloc(sizeof(zval), htl->nNumOfElements, 0);
for (idx = 0; idx < htl->nNumUsed; idx++) {
p = htl->arData + idx;
- if (!p->xData) continue;
- fci.params[fci.param_count++] = (zval**)&p->xData;
+ if (ZVAL_IS_NULL(&p->val)) continue;
+ ZVAL_COPY_VALUE(&fci.params[fci.param_count++], &p->val);
}
} else {
/* Two problems why we throw exceptions here: PHP is typeless
@@ -2206,20 +2212,20 @@ static void php_mysql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type,
fcc.function_handler = ce->constructor;
fcc.calling_scope = EG(scope);
fcc.called_scope = Z_OBJCE_P(return_value);
- fcc.object_ptr = return_value;
+ ZVAL_COPY_VALUE(&fcc.object, return_value);
if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) {
- zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Could not execute %s::%s()", ce->name, ce->constructor->common.function_name);
+ zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Could not execute %s::%s()", ce->name->val, ce->constructor->common.function_name->val);
} else {
- if (retval_ptr) {
- zval_ptr_dtor(&retval_ptr);
+ if (!ZVAL_IS_UNDEF(&retval)) {
+ zval_ptr_dtor(&retval);
}
}
if (fci.params) {
efree(fci.params);
}
} else if (ctor_params) {
- zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Class %s does not have a constructor hence you cannot use ctor_params", ce->name);
+ zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Class %s does not have a constructor hence you cannot use ctor_params", ce->name->val);
}
}
#endif
@@ -2235,7 +2241,6 @@ PHP_FUNCTION(mysql_fetch_row)
}
/* }}} */
-
/* {{{ proto object mysql_fetch_object(resource result [, string class_name [, NULL|array ctor_params]])
Fetch a result row as an object */
PHP_FUNCTION(mysql_fetch_object)
@@ -2248,7 +2253,6 @@ PHP_FUNCTION(mysql_fetch_object)
}
/* }}} */
-
/* {{{ proto array mysql_fetch_array(resource result [, int result_type])
Fetch a result row as an array (associative, numeric or both) */
PHP_FUNCTION(mysql_fetch_array)
@@ -2257,7 +2261,6 @@ PHP_FUNCTION(mysql_fetch_array)
}
/* }}} */
-
/* {{{ proto array mysql_fetch_assoc(resource result)
Fetch a result row as an associative array */
PHP_FUNCTION(mysql_fetch_assoc)
@@ -2278,10 +2281,10 @@ PHP_FUNCTION(mysql_data_seek)
return;
}
- ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, &result, -1, "MySQL result", le_result);
+ ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, result, -1, "MySQL result", le_result);
- if (offset<0 || offset>=(int)mysql_num_rows(mysql_result)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset %ld is invalid for MySQL result index %ld (or the query data is unbuffered)", offset, Z_LVAL_P(result));
+ if (offset < 0 || offset >= (int)mysql_num_rows(mysql_result)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset %ld is invalid for MySQL result index %ld (or the query data is unbuffered)", offset, Z_RES_P(result)->handle);
RETURN_FALSE;
}
mysql_data_seek(mysql_result, offset);
@@ -2289,7 +2292,6 @@ PHP_FUNCTION(mysql_data_seek)
}
/* }}} */
-
/* {{{ proto array mysql_fetch_lengths(resource result)
Gets max data size of each column in a result */
PHP_FUNCTION(mysql_fetch_lengths)
@@ -2304,7 +2306,7 @@ PHP_FUNCTION(mysql_fetch_lengths)
return;
}
- ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, &result, -1, "MySQL result", le_result);
+ ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, result, -1, "MySQL result", le_result);
if ((lengths=mysql_fetch_lengths(mysql_result))==NULL) {
RETURN_FALSE;
@@ -2407,37 +2409,36 @@ PHP_FUNCTION(mysql_fetch_field)
return;
}
- ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, &result, -1, "MySQL result", le_result);
+ ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, result, -1, "MySQL result", le_result);
if (ZEND_NUM_ARGS() > 1) {
- if (field<0 || field>=(int)mysql_num_fields(mysql_result)) {
+ if (field<0 || field >= (int)mysql_num_fields(mysql_result)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad field offset");
RETURN_FALSE;
}
mysql_field_seek(mysql_result, field);
}
- if ((mysql_field=mysql_fetch_field(mysql_result))==NULL) {
+ if ((mysql_field = mysql_fetch_field(mysql_result)) == NULL) {
RETURN_FALSE;
}
object_init(return_value);
- add_property_string(return_value, "name",(mysql_field->name?mysql_field->name:""), 1);
- add_property_string(return_value, "table",(mysql_field->table?mysql_field->table:""), 1);
- add_property_string(return_value, "def",(mysql_field->def?mysql_field->def:""), 1);
+ add_property_string(return_value, "name", (mysql_field->name?mysql_field->name:""), 1);
+ add_property_string(return_value, "table", (mysql_field->table?mysql_field->table:""), 1);
+ add_property_string(return_value, "def", (mysql_field->def?mysql_field->def:""), 1);
add_property_long(return_value, "max_length", mysql_field->max_length);
add_property_long(return_value, "not_null", IS_NOT_NULL(mysql_field->flags)?1:0);
add_property_long(return_value, "primary_key", IS_PRI_KEY(mysql_field->flags)?1:0);
- add_property_long(return_value, "multiple_key",(mysql_field->flags&MULTIPLE_KEY_FLAG?1:0));
- add_property_long(return_value, "unique_key",(mysql_field->flags&UNIQUE_KEY_FLAG?1:0));
+ add_property_long(return_value, "multiple_key", (mysql_field->flags&MULTIPLE_KEY_FLAG?1:0));
+ add_property_long(return_value, "unique_key", (mysql_field->flags&UNIQUE_KEY_FLAG?1:0));
add_property_long(return_value, "numeric", IS_NUM(Z_TYPE_P(mysql_field))?1:0);
add_property_long(return_value, "blob", IS_BLOB(mysql_field->flags)?1:0);
add_property_string(return_value, "type", php_mysql_get_field_name(Z_TYPE_P(mysql_field)), 1);
- add_property_long(return_value, "unsigned",(mysql_field->flags&UNSIGNED_FLAG?1:0));
- add_property_long(return_value, "zerofill",(mysql_field->flags&ZEROFILL_FLAG?1:0));
+ add_property_long(return_value, "unsigned", (mysql_field->flags&UNSIGNED_FLAG?1:0));
+ add_property_long(return_value, "zerofill", (mysql_field->flags&ZEROFILL_FLAG?1:0));
}
/* }}} */
-
/* {{{ proto bool mysql_field_seek(resource result, int field_offset)
Sets result pointer to a specific field offset */
PHP_FUNCTION(mysql_field_seek)
@@ -2449,10 +2450,10 @@ PHP_FUNCTION(mysql_field_seek)
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &result, &offset) == FAILURE) {
return;
}
- ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, &result, -1, "MySQL result", le_result);
+ ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, result, -1, "MySQL result", le_result);
- if (offset<0 || offset>=(int)mysql_num_fields(mysql_result)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Field %ld is invalid for MySQL result index %ld", offset, Z_LVAL_P(result));
+ if (offset < 0 || offset >= (int)mysql_num_fields(mysql_result)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Field %ld is invalid for MySQL result index %ld", offset, Z_RES_P(result)->handle);
RETURN_FALSE;
}
mysql_field_seek(mysql_result, offset);
@@ -2460,7 +2461,6 @@ PHP_FUNCTION(mysql_field_seek)
}
/* }}} */
-
#define PHP_MYSQL_FIELD_NAME 1
#define PHP_MYSQL_FIELD_TABLE 2
#define PHP_MYSQL_FIELD_LEN 3
@@ -2482,10 +2482,10 @@ static void php_mysql_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
return;
}
- ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, &result, -1, "MySQL result", le_result);
+ ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, result, -1, "MySQL result", le_result);
- if (field<0 || field>=(int)mysql_num_fields(mysql_result)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Field %ld is invalid for MySQL result index %ld", field, Z_LVAL_P(result));
+ if (field < 0 || field >= (int)mysql_num_fields(mysql_result)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Field %ld is invalid for MySQL result index %ld", field, Z_RES_P(result)->handle);
RETURN_FALSE;
}
mysql_field_seek(mysql_result, field);
@@ -2495,24 +2495,16 @@ static void php_mysql_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
switch (entry_type) {
case PHP_MYSQL_FIELD_NAME:
- Z_STRLEN_P(return_value) = strlen(mysql_field->name);
- Z_STRVAL_P(return_value) = estrndup(mysql_field->name, Z_STRLEN_P(return_value));
- Z_TYPE_P(return_value) = IS_STRING;
+ RETVAL_STRING(mysql_field->name);
break;
case PHP_MYSQL_FIELD_TABLE:
- Z_STRLEN_P(return_value) = strlen(mysql_field->table);
- Z_STRVAL_P(return_value) = estrndup(mysql_field->table, Z_STRLEN_P(return_value));
- Z_TYPE_P(return_value) = IS_STRING;
+ RETVAL_STRING(mysql_field->table);
break;
case PHP_MYSQL_FIELD_LEN:
- Z_LVAL_P(return_value) = mysql_field->length;
- Z_TYPE_P(return_value) = IS_LONG;
+ RETVAL_LONG(mysql_field->length);
break;
case PHP_MYSQL_FIELD_TYPE:
- Z_STRVAL_P(return_value) = php_mysql_get_field_name(Z_TYPE_P(mysql_field));
- Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
- Z_STRVAL_P(return_value) = estrndup(Z_STRVAL_P(return_value), Z_STRLEN_P(return_value));
- Z_TYPE_P(return_value) = IS_STRING;
+ RETVAL_STRING(php_mysql_get_field_name(Z_TYPE_P(mysql_field)));
break;
case PHP_MYSQL_FIELD_FLAGS:
memcpy(buf, "", sizeof(""));
@@ -2583,9 +2575,7 @@ static void php_mysql_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
len--;
}
- Z_STRLEN_P(return_value) = len;
- Z_STRVAL_P(return_value) = estrndup(buf, len);
- Z_TYPE_P(return_value) = IS_STRING;
+ RETVAL_STRINGL(buf, len);
break;
default:
@@ -2602,7 +2592,6 @@ PHP_FUNCTION(mysql_field_name)
}
/* }}} */
-
/* {{{ proto string mysql_field_table(resource result, int field_offset)
Gets name of the table the specified field is in */
PHP_FUNCTION(mysql_field_table)
@@ -2611,7 +2600,6 @@ PHP_FUNCTION(mysql_field_table)
}
/* }}} */
-
/* {{{ proto int mysql_field_len(resource result, int field_offset)
Returns the length of the specified field */
PHP_FUNCTION(mysql_field_len)
@@ -2620,7 +2608,6 @@ PHP_FUNCTION(mysql_field_len)
}
/* }}} */
-
/* {{{ proto string mysql_field_type(resource result, int field_offset)
Gets the type of the specified field in a result */
PHP_FUNCTION(mysql_field_type)
@@ -2629,7 +2616,6 @@ PHP_FUNCTION(mysql_field_type)
}
/* }}} */
-
/* {{{ proto string mysql_field_flags(resource result, int field_offset)
Gets the flags associated with the specified field in a result */
PHP_FUNCTION(mysql_field_flags)
@@ -2638,7 +2624,6 @@ PHP_FUNCTION(mysql_field_flags)
}
/* }}} */
-
/* {{{ proto bool mysql_free_result(resource result)
Free result memory */
PHP_FUNCTION(mysql_free_result)
@@ -2650,13 +2635,9 @@ PHP_FUNCTION(mysql_free_result)
return;
}
- if (Z_LVAL_P(result)==0) {
- RETURN_FALSE;
- }
-
- ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, &result, -1, "MySQL result", le_result);
+ ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, result, -1, "MySQL result", le_result);
- zend_list_delete(Z_LVAL_P(result));
+ zend_list_close(Z_RES_P(result));
RETURN_TRUE;
}
/* }}} */
@@ -2665,22 +2646,24 @@ PHP_FUNCTION(mysql_free_result)
Ping a server connection. If no connection then reconnect. */
PHP_FUNCTION(mysql_ping)
{
- zval *mysql_link = NULL;
- int id = -1;
php_mysql_conn *mysql;
+ zval *mysql_link = NULL;
- if (0 == ZEND_NUM_ARGS()) {
- id = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- CHECK_LINK(id);
- } else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &mysql_link)==FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &mysql_link)==FAILURE) {
return;
}
- ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, &mysql_link, id, "MySQL-Link", le_link, le_plink);
+ if (!mysql_link) {
+ zend_resource *res = php_mysql_get_default_link(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ CHECK_LINK(res);
+ mysql = (php_mysql_conn*)res->ptr;
+ } else {
+ ZEND_FETCH_RESOURCE2(mysql, php_mysql_conn *, mysql_link, -1, "MySQL-Link", le_link, le_plink);
+ }
PHPMY_UNBUFFERED_QUERY_CHECK();
- RETURN_BOOL(! mysql_ping(mysql->conn));
+ RETURN_BOOL(!mysql_ping(mysql->conn));
}
/* }}} */
diff --git a/ext/mysql/php_mysql_structs.h b/ext/mysql/php_mysql_structs.h
index ee1286d989..0e8ab482a1 100644
--- a/ext/mysql/php_mysql_structs.h
+++ b/ext/mysql/php_mysql_structs.h
@@ -111,7 +111,7 @@ PHP_FUNCTION(mysql_set_charset);
#endif
ZEND_BEGIN_MODULE_GLOBALS(mysql)
- long default_link;
+ zend_resource *default_link;
long num_links,num_persistent;
long max_links,max_persistent;
long allow_persistent;
diff --git a/ext/mysql/tests/mysql_data_seek.phpt b/ext/mysql/tests/mysql_data_seek.phpt
index 72d3e63274..268e145842 100644
--- a/ext/mysql/tests/mysql_data_seek.phpt
+++ b/ext/mysql/tests/mysql_data_seek.phpt
@@ -75,5 +75,5 @@ Warning: mysql_data_seek(): Offset -1 is invalid for MySQL result index %d (or t
Warning: mysql_data_seek(): Offset 3 is invalid for MySQL result index %d (or the query data is unbuffered) in %s on line %d
-Warning: mysql_data_seek(): %d is not a valid MySQL result resource in %s on line %d
+Warning: mysql_data_seek(): supplied resource is not a valid MySQL result resource in %s on line %d
done!
diff --git a/ext/mysql/tests/mysql_db_name.phpt b/ext/mysql/tests/mysql_db_name.phpt
index 92878e994d..9321701337 100644
--- a/ext/mysql/tests/mysql_db_name.phpt
+++ b/ext/mysql/tests/mysql_db_name.phpt
@@ -64,5 +64,5 @@ Warning: mysql_db_name(): Unable to jump to row -1 on MySQL result index %d in %
Warning: mysql_db_name(): Unable to jump to row %d on MySQL result index %d in %s on line %d
-Warning: mysql_db_name(): %d is not a valid MySQL result resource in %s on line %d
+Warning: mysql_db_name(): supplied resource is not a valid MySQL result resource in %s on line %d
done!
diff --git a/ext/mysql/tests/mysql_errno.phpt b/ext/mysql/tests/mysql_errno.phpt
index c9c2956290..83aa7327bd 100644
--- a/ext/mysql/tests/mysql_errno.phpt
+++ b/ext/mysql/tests/mysql_errno.phpt
@@ -59,6 +59,6 @@ Deprecated: mysql_connect(): The mysql extension is deprecated and will be remov
int(0)
int(%d)
-Warning: mysql_errno(): %d is not a valid MySQL-Link resource in %s on line %d
+Warning: mysql_errno(): supplied resource is not a valid MySQL-Link resource in %s on line %d
bool(false)
done!
diff --git a/ext/mysql/tests/mysql_error.phpt b/ext/mysql/tests/mysql_error.phpt
index a2cf7e0034..82a43fb7b4 100644
--- a/ext/mysql/tests/mysql_error.phpt
+++ b/ext/mysql/tests/mysql_error.phpt
@@ -64,6 +64,6 @@ require_once("clean_table.inc");
--EXPECTF--
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
-Warning: mysql_error(): %d is not a valid MySQL-Link resource in %s on line %d
+Warning: mysql_error(): supplied resource is not a valid MySQL-Link resource in %s on line %d
bool(false)
done!
diff --git a/ext/mysql/tests/mysql_fetch_array.phpt b/ext/mysql/tests/mysql_fetch_array.phpt
index 8ccefd0242..1b1852d932 100644
--- a/ext/mysql/tests/mysql_fetch_array.phpt
+++ b/ext/mysql/tests/mysql_fetch_array.phpt
@@ -357,5 +357,5 @@ array(11) {
Warning: mysql_fetch_array(): The result type should be either MYSQL_NUM, MYSQL_ASSOC or MYSQL_BOTH in %s on line %d
-Warning: mysql_fetch_array(): %d is not a valid MySQL result resource in %s on line %d
+Warning: mysql_fetch_array(): supplied resource is not a valid MySQL result resource in %s on line %d
done!
diff --git a/ext/mysql/tests/mysql_fetch_assoc.phpt b/ext/mysql/tests/mysql_fetch_assoc.phpt
index 048613a6be..936c7c6f23 100644
--- a/ext/mysql/tests/mysql_fetch_assoc.phpt
+++ b/ext/mysql/tests/mysql_fetch_assoc.phpt
@@ -87,7 +87,7 @@ array(5) {
%unicode|string%(1) "1"
}
-Warning: mysql_fetch_assoc(): %d is not a valid MySQL result resource in %s on line %d
+Warning: mysql_fetch_assoc(): supplied resource is not a valid MySQL result resource in %s on line %d
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
[010]
diff --git a/ext/mysql/tests/mysql_fetch_field.phpt b/ext/mysql/tests/mysql_fetch_field.phpt
index 85c1fd6f7e..6855fc52dc 100644
--- a/ext/mysql/tests/mysql_fetch_field.phpt
+++ b/ext/mysql/tests/mysql_fetch_field.phpt
@@ -217,7 +217,7 @@ bool(false)
Warning: mysql_fetch_field(): Bad field offset in %s on line %d
-Warning: mysql_fetch_field(): %d is not a valid MySQL result resource in %s on line %d
+Warning: mysql_fetch_field(): supplied resource is not a valid MySQL result resource in %s on line %d
object(stdClass)#%d (13) {
[%u|b%"name"]=>
%unicode|string%(2) "id"
diff --git a/ext/mysql/tests/mysql_fetch_lengths.phpt b/ext/mysql/tests/mysql_fetch_lengths.phpt
index f0fbbb7bb8..f59833e918 100644
--- a/ext/mysql/tests/mysql_fetch_lengths.phpt
+++ b/ext/mysql/tests/mysql_fetch_lengths.phpt
@@ -48,6 +48,6 @@ array(2) {
}
bool(false)
-Warning: mysql_fetch_lengths(): %d is not a valid MySQL result resource in %s on line %d
+Warning: mysql_fetch_lengths(): supplied resource is not a valid MySQL result resource in %s on line %d
bool(false)
done!
diff --git a/ext/mysql/tests/mysql_fetch_object.phpt b/ext/mysql/tests/mysql_fetch_object.phpt
index 666d0ee821..5038863458 100644
--- a/ext/mysql/tests/mysql_fetch_object.phpt
+++ b/ext/mysql/tests/mysql_fetch_object.phpt
@@ -147,7 +147,7 @@ bool(false)
bool(false)
bool(false)
-Warning: mysql_fetch_object(): %d is not a valid MySQL result resource in %s on line %d
+Warning: mysql_fetch_object(): supplied resource is not a valid MySQL result resource in %s on line %d
bool(false)
Fatal error: Class 'this_class_does_not_exist' not found in %s on line %d
diff --git a/ext/mysql/tests/mysql_fetch_row.phpt b/ext/mysql/tests/mysql_fetch_row.phpt
index 0ed932e2c0..d26f7a4d82 100644
--- a/ext/mysql/tests/mysql_fetch_row.phpt
+++ b/ext/mysql/tests/mysql_fetch_row.phpt
@@ -52,6 +52,6 @@ array(2) {
[005]
bool(false)
-Warning: mysql_fetch_row(): %d is not a valid MySQL result resource in %s on line %d
+Warning: mysql_fetch_row(): supplied resource is not a valid MySQL result resource in %s on line %d
bool(false)
done!
diff --git a/ext/mysql/tests/mysql_field_flags.phpt b/ext/mysql/tests/mysql_field_flags.phpt
index 5f8eb0995f..cd9e4b5671 100644
--- a/ext/mysql/tests/mysql_field_flags.phpt
+++ b/ext/mysql/tests/mysql_field_flags.phpt
@@ -152,6 +152,6 @@ Warning: mysql_field_flags(): Field -1 is invalid for MySQL result index %d in %
Warning: mysql_field_flags(): Field 2 is invalid for MySQL result index %d in %s on line %d
-Warning: mysql_field_flags(): %d is not a valid MySQL result resource in %s on line %d
+Warning: mysql_field_flags(): supplied resource is not a valid MySQL result resource in %s on line %d
bool(false)
done!
diff --git a/ext/mysql/tests/mysql_field_len.phpt b/ext/mysql/tests/mysql_field_len.phpt
index 119d352164..a7b4cabee3 100644
--- a/ext/mysql/tests/mysql_field_len.phpt
+++ b/ext/mysql/tests/mysql_field_len.phpt
@@ -55,6 +55,6 @@ Warning: mysql_field_len(): Field -1 is invalid for MySQL result index %d in %s
Warning: mysql_field_len(): Field 2 is invalid for MySQL result index %d in %s on line %d
-Warning: mysql_field_len(): %d is not a valid MySQL result resource in %s on line %d
+Warning: mysql_field_len(): supplied resource is not a valid MySQL result resource in %s on line %d
bool(false)
done!
diff --git a/ext/mysql/tests/mysql_field_name.phpt b/ext/mysql/tests/mysql_field_name.phpt
index 85f6c42d93..1ef613babe 100644
--- a/ext/mysql/tests/mysql_field_name.phpt
+++ b/ext/mysql/tests/mysql_field_name.phpt
@@ -55,6 +55,6 @@ Warning: mysql_field_name(): Field -1 is invalid for MySQL result index %d in %s
Warning: mysql_field_name(): Field 2 is invalid for MySQL result index %d in %s on line %d
-Warning: mysql_field_name(): %d is not a valid MySQL result resource in %s on line %d
+Warning: mysql_field_name(): supplied resource is not a valid MySQL result resource in %s on line %d
bool(false)
done!
diff --git a/ext/mysql/tests/mysql_field_seek.phpt b/ext/mysql/tests/mysql_field_seek.phpt
index 8487493a88..a9eab70bca 100644
--- a/ext/mysql/tests/mysql_field_seek.phpt
+++ b/ext/mysql/tests/mysql_field_seek.phpt
@@ -139,6 +139,6 @@ Warning: mysql_field_seek(): Field %d is invalid for MySQL result index %d in %s
bool(false)
bool(false)
-Warning: mysql_field_seek(): %d is not a valid MySQL result resource in %s on line %d
+Warning: mysql_field_seek(): supplied resource is not a valid MySQL result resource in %s on line %d
bool(false)
done!
diff --git a/ext/mysql/tests/mysql_field_table.phpt b/ext/mysql/tests/mysql_field_table.phpt
index 826651a855..d95be96ee5 100644
--- a/ext/mysql/tests/mysql_field_table.phpt
+++ b/ext/mysql/tests/mysql_field_table.phpt
@@ -55,6 +55,6 @@ Warning: mysql_field_table(): Field -1 is invalid for MySQL result index %d in %
Warning: mysql_field_table(): Field 2 is invalid for MySQL result index %d in %s on line %d
-Warning: mysql_field_table(): %d is not a valid MySQL result resource in %s on line %d
+Warning: mysql_field_table(): supplied resource is not a valid MySQL result resource in %s on line %d
bool(false)
done!
diff --git a/ext/mysql/tests/mysql_field_type.phpt b/ext/mysql/tests/mysql_field_type.phpt
index c767cab6f1..e4b774a691 100644
--- a/ext/mysql/tests/mysql_field_type.phpt
+++ b/ext/mysql/tests/mysql_field_type.phpt
@@ -55,6 +55,6 @@ Warning: mysql_field_type(): Field -1 is invalid for MySQL result index %d in %s
Warning: mysql_field_type(): Field 2 is invalid for MySQL result index %d in %s on line %d
-Warning: mysql_field_type(): %d is not a valid MySQL result resource in %s on line %d
+Warning: mysql_field_type(): supplied resource is not a valid MySQL result resource in %s on line %d
bool(false)
done!
diff --git a/ext/mysql/tests/mysql_free_result.phpt b/ext/mysql/tests/mysql_free_result.phpt
index 90498bd59a..582297c80f 100644
--- a/ext/mysql/tests/mysql_free_result.phpt
+++ b/ext/mysql/tests/mysql_free_result.phpt
@@ -47,6 +47,6 @@ require_once("clean_table.inc");
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
bool(true)
-Warning: mysql_free_result(): %d is not a valid MySQL result resource in %s on line %d
+Warning: mysql_free_result(): supplied resource is not a valid MySQL result resource in %s on line %d
bool(false)
done!
diff --git a/ext/mysql/tests/mysql_insert_id.phpt b/ext/mysql/tests/mysql_insert_id.phpt
index b69a96ae9b..93319dad23 100644
--- a/ext/mysql/tests/mysql_insert_id.phpt
+++ b/ext/mysql/tests/mysql_insert_id.phpt
@@ -68,6 +68,6 @@ require_once("clean_table.inc");
--EXPECTF--
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
-Warning: mysql_insert_id(): %d is not a valid MySQL-Link resource in %s on line %d
+Warning: mysql_insert_id(): supplied resource is not a valid MySQL-Link resource in %s on line %d
bool(false)
done!
diff --git a/ext/mysql/tests/mysql_num_fields.phpt b/ext/mysql/tests/mysql_num_fields.phpt
index 4621dc91f8..f65f8ec165 100644
--- a/ext/mysql/tests/mysql_num_fields.phpt
+++ b/ext/mysql/tests/mysql_num_fields.phpt
@@ -54,5 +54,5 @@ require_once("clean_table.inc");
--EXPECTF--
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
-Warning: mysql_num_fields(): %d is not a valid MySQL result resource in %s on line %d
+Warning: mysql_num_fields(): supplied resource is not a valid MySQL result resource in %s on line %d
done!
diff --git a/ext/mysql/tests/mysql_num_rows.phpt b/ext/mysql/tests/mysql_num_rows.phpt
index 5a803d41f9..2b69e939be 100644
--- a/ext/mysql/tests/mysql_num_rows.phpt
+++ b/ext/mysql/tests/mysql_num_rows.phpt
@@ -85,5 +85,5 @@ Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in %
Warning: mysql_free_result() expects parameter 1 to be resource, boolean given in %s on line %d
-Warning: mysql_num_rows(): %d is not a valid MySQL result resource in %s on line %d
+Warning: mysql_num_rows(): supplied resource is not a valid MySQL result resource in %s on line %d
done!
diff --git a/ext/mysql/tests/mysql_ping.phpt b/ext/mysql/tests/mysql_ping.phpt
index 0308df3396..2f2c38cd90 100644
--- a/ext/mysql/tests/mysql_ping.phpt
+++ b/ext/mysql/tests/mysql_ping.phpt
@@ -47,5 +47,5 @@ bool(true)
bool(true)
bool(true)
-Warning: mysql_ping(): %d is not a valid MySQL-Link resource in %s on line %d
+Warning: mysql_ping(): supplied resource is not a valid MySQL-Link resource in %s on line %d
done!
diff --git a/ext/mysql/tests/mysql_query.phpt b/ext/mysql/tests/mysql_query.phpt
index 01b14ee284..80b985e099 100644
--- a/ext/mysql/tests/mysql_query.phpt
+++ b/ext/mysql/tests/mysql_query.phpt
@@ -124,5 +124,5 @@ array(1) {
}
%unicode|string%(1) "a"
-Warning: mysql_query(): %d is not a valid MySQL-Link resource in %s on line %d
+Warning: mysql_query(): supplied resource is not a valid MySQL-Link resource in %s on line %d
done!
diff --git a/ext/mysql/tests/mysql_result.phpt b/ext/mysql/tests/mysql_result.phpt
index 0a58b9b883..ae1983fe04 100644
--- a/ext/mysql/tests/mysql_result.phpt
+++ b/ext/mysql/tests/mysql_result.phpt
@@ -111,6 +111,6 @@ bool(false)
Warning: mysql_result(): test.label not found in MySQL result index %d in %s on line %d
bool(false)
-Warning: mysql_result(): %d is not a valid MySQL result resource in %s on line %d
+Warning: mysql_result(): supplied resource is not a valid MySQL result resource in %s on line %d
bool(false)
done!
diff --git a/ext/mysql/tests/mysql_select_db.phpt b/ext/mysql/tests/mysql_select_db.phpt
index e9bc99aa73..6e0bf9e505 100644
--- a/ext/mysql/tests/mysql_select_db.phpt
+++ b/ext/mysql/tests/mysql_select_db.phpt
@@ -70,5 +70,5 @@ Deprecated: mysql_connect(): The mysql extension is deprecated and will be remov
%unicode|string%(%d) "%s"
bool(false)
-Warning: mysql_select_db(): %d is not a valid MySQL-Link resource in %s on line %d
+Warning: mysql_select_db(): supplied resource is not a valid MySQL-Link resource in %s on line %d
done!
diff --git a/ext/mysql/tests/mysql_stat.phpt b/ext/mysql/tests/mysql_stat.phpt
index d6a34df581..ef5bb45105 100644
--- a/ext/mysql/tests/mysql_stat.phpt
+++ b/ext/mysql/tests/mysql_stat.phpt
@@ -46,5 +46,5 @@ print "done!";
--EXPECTF--
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
-Warning: mysql_stat(): %d is not a valid MySQL-Link resource in %s on line %d
+Warning: mysql_stat(): supplied resource is not a valid MySQL-Link resource in %s on line %d
done!
diff --git a/ext/mysql/tests/mysql_tablename.phpt b/ext/mysql/tests/mysql_tablename.phpt
index 4bbe54d443..76007fde46 100644
--- a/ext/mysql/tests/mysql_tablename.phpt
+++ b/ext/mysql/tests/mysql_tablename.phpt
@@ -51,6 +51,6 @@ Warning: mysql_tablename(): Unable to jump to row -1 on MySQL result index %d in
Warning: mysql_tablename(): Unable to jump to row 2 on MySQL result index %d in %s on line %d
-Warning: mysql_tablename(): %d is not a valid MySQL result resource in %s on line %d
+Warning: mysql_tablename(): supplied resource is not a valid MySQL result resource in %s on line %d
bool(false)
done!
diff --git a/ext/mysql/tests/mysql_thread_id.phpt b/ext/mysql/tests/mysql_thread_id.phpt
index aa95d31944..a2e0f934c2 100644
--- a/ext/mysql/tests/mysql_thread_id.phpt
+++ b/ext/mysql/tests/mysql_thread_id.phpt
@@ -37,5 +37,5 @@ print "done!";
--EXPECTF--
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
-Warning: mysql_thread_id(): %d is not a valid MySQL-Link resource in %s on line %d
+Warning: mysql_thread_id(): supplied resource is not a valid MySQL-Link resource in %s on line %d
done!
diff --git a/ext/mysql/tests/mysql_unbuffered_query.phpt b/ext/mysql/tests/mysql_unbuffered_query.phpt
index 8754b58b59..5b10cc41d9 100644
--- a/ext/mysql/tests/mysql_unbuffered_query.phpt
+++ b/ext/mysql/tests/mysql_unbuffered_query.phpt
@@ -118,5 +118,5 @@ int(0)
Notice: mysql_close(): Function called without first fetching all rows from a previous unbuffered query in %s on line %d
-Warning: mysql_unbuffered_query(): %d is not a valid MySQL-Link resource in %s on line %d
+Warning: mysql_unbuffered_query(): supplied resource is not a valid MySQL-Link resource in %s on line %d
done!
diff --git a/ext/mysql/tests/setupdefault.inc b/ext/mysql/tests/setupdefault.inc
index 6d25c20840..b13402ec14 100644
--- a/ext/mysql/tests/setupdefault.inc
+++ b/ext/mysql/tests/setupdefault.inc
@@ -3,7 +3,7 @@
// copy variables from connect.inc into mysql default connection ini settings, so that implicit mysql_connect() behaviour can be tested where needed
// must be loaded AFTER connect.inc
-ini_set('mysql.default_host', $host);
+ini_set('mysql.default_host', $host . ":" . $port);
ini_set('mysql.default_user', $user);
ini_set('mysql.default_password', $passwd);