diff options
author | Andrey Hristov <andrey@php.net> | 2010-01-25 13:23:32 +0000 |
---|---|---|
committer | Andrey Hristov <andrey@php.net> | 2010-01-25 13:23:32 +0000 |
commit | 6407250e70534234379712a2050efc5ddb437958 (patch) | |
tree | edb895f3de78be404a0a530131580c678627b6af /ext | |
parent | db8a6974fb44c47537a4979178e23640f6dc898f (diff) | |
download | php-git-6407250e70534234379712a2050efc5ddb437958.tar.gz |
Fix for bug#50772
mysqli constructor without parameters does not return a working mysqli object
Diffstat (limited to 'ext')
-rw-r--r-- | ext/mysqli/mysqli_api.c | 15 | ||||
-rw-r--r-- | ext/mysqli/mysqli_nonapi.c | 3 | ||||
-rw-r--r-- | ext/mysqli/php_mysqli_structs.h | 2 | ||||
-rw-r--r-- | ext/mysqli/tests/bug50772.phpt | 36 |
4 files changed, 52 insertions, 4 deletions
diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index 43b60848ca..5c9cd6e0a2 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -1333,9 +1333,9 @@ PHP_FUNCTION(mysqli_info) } /* }}} */ -/* {{{ proto resource mysqli_init(void) - Initialize mysqli and return a resource for use with mysql_real_connect */ -PHP_FUNCTION(mysqli_init) + +/* {{{ php_mysqli_init() */ +void php_mysqli_init(INTERNAL_FUNCTION_PARAMETERS) { MYSQLI_RESOURCE *mysqli_resource; MY_MYSQL *mysql; @@ -1372,6 +1372,15 @@ PHP_FUNCTION(mysqli_init) } /* }}} */ + +/* {{{ proto resource mysqli_init(void) + Initialize mysqli and return a resource for use with mysql_real_connect */ +PHP_FUNCTION(mysqli_init) +{ + php_mysqli_init(INTERNAL_FUNCTION_PARAM_PASSTHRU); +} +/* }}} */ + /* {{{ proto mixed mysqli_insert_id(object link) Get the ID generated from the previous INSERT operation */ PHP_FUNCTION(mysqli_insert_id) diff --git a/ext/mysqli/mysqli_nonapi.c b/ext/mysqli/mysqli_nonapi.c index 9cbf8d2607..b3b0dded08 100644 --- a/ext/mysqli/mysqli_nonapi.c +++ b/ext/mysqli/mysqli_nonapi.c @@ -80,7 +80,8 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne #endif if (getThis() && !ZEND_NUM_ARGS() && in_ctor) { - RETURN_NULL(); + php_mysqli_init(INTERNAL_FUNCTION_PARAM_PASSTHRU); + return; } hostname = username = dbname = passwd = socket = NULL; diff --git a/ext/mysqli/php_mysqli_structs.h b/ext/mysqli/php_mysqli_structs.h index 7625378579..ecf91518fb 100644 --- a/ext/mysqli/php_mysqli_structs.h +++ b/ext/mysqli/php_mysqli_structs.h @@ -338,6 +338,8 @@ if ((MyG(report_mode) & MYSQLI_REPORT_ERROR) && mysql_stmt_errno(stmt)) { \ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_connect, zend_bool in_ctor); +void php_mysqli_init(INTERNAL_FUNCTION_PARAMETERS); + ZEND_BEGIN_MODULE_GLOBALS(mysqli) long default_link; diff --git a/ext/mysqli/tests/bug50772.phpt b/ext/mysqli/tests/bug50772.phpt new file mode 100644 index 0000000000..4724d0f29e --- /dev/null +++ b/ext/mysqli/tests/bug50772.phpt @@ -0,0 +1,36 @@ +--TEST-- +Bug #50772 (mysqli constructor without parameters does not return a working mysqli object) +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + include "connect.inc"; + $db1 = new mysqli(); + + // These calls fail + $db1->options(MYSQLI_OPT_CONNECT_TIMEOUT, 3); + $db1->real_connect($host, $user, $passwd); + if(mysqli_connect_error()) { + echo "error 1\n"; + } else { + echo "ok 1\n"; + } + + $db2 = mysqli_init(); + + $db2->options(MYSQLI_OPT_CONNECT_TIMEOUT, 3); + $db2->real_connect($host, $user, $passwd); + if(mysqli_connect_error()) { + echo "error 2\n"; + } else { + echo "ok 2\n"; + } + echo "done\n"; +?> +--EXPECTF-- +ok 1 +ok 2 +done
\ No newline at end of file |