andrey Mon, 25 Jan 2010 13:23:32 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=293976
Log:
Fix for bug#50772
mysqli constructor without parameters does not return a working mysqli object
Bug: http://bugs.php.net/50772 (Assigned) mysqli constructor without parameters
does not return a working mysqli object
Changed paths:
U php/php-src/branches/PHP_5_2/NEWS
U php/php-src/branches/PHP_5_2/ext/mysqli/mysqli_api.c
U php/php-src/branches/PHP_5_2/ext/mysqli/mysqli_nonapi.c
U php/php-src/branches/PHP_5_2/ext/mysqli/php_mysqli.h
A php/php-src/branches/PHP_5_2/ext/mysqli/tests/bug50772.phpt
U php/php-src/branches/PHP_5_2/ext/mysqli/tests/connect.inc
U php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_api.c
U php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_nonapi.c
U php/php-src/branches/PHP_5_3/ext/mysqli/php_mysqli_structs.h
A php/php-src/branches/PHP_5_3/ext/mysqli/tests/bug50772.phpt
U php/php-src/trunk/ext/mysqli/mysqli_api.c
U php/php-src/trunk/ext/mysqli/mysqli_nonapi.c
U php/php-src/trunk/ext/mysqli/php_mysqli_structs.h
A php/php-src/trunk/ext/mysqli/tests/bug50772.phpt
Modified: php/php-src/branches/PHP_5_2/NEWS
===================================================================
--- php/php-src/branches/PHP_5_2/NEWS 2010-01-25 13:22:58 UTC (rev 293975)
+++ php/php-src/branches/PHP_5_2/NEWS 2010-01-25 13:23:32 UTC (rev 293976)
@@ -24,6 +24,8 @@
emulation). (Jani)
- Fixed bug #50787 (stream_set_write_buffer() has no effect on socket
streams). (vnegrier at optilian dot com, Ilia)
+- Fixed bug #50772 (mysqli constructor without parameters does not return a
+ working mysqli object). (Andrey)
- Fixed bug #50761 (system.multiCall crashes in xmlrpc extension). (hiroaki
dot kawai at gmail dot com, Ilia)
- Fixed bug #50732 (exec() adds single byte twice to $output array). (Ilia)
Modified: php/php-src/branches/PHP_5_2/ext/mysqli/mysqli_api.c
===================================================================
--- php/php-src/branches/PHP_5_2/ext/mysqli/mysqli_api.c 2010-01-25 13:22:58 UTC (rev 293975)
+++ php/php-src/branches/PHP_5_2/ext/mysqli/mysqli_api.c 2010-01-25 13:23:32 UTC (rev 293976)
@@ -1094,9 +1094,9 @@
}
/* }}} */
-/* {{{ 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;
@@ -1121,9 +1121,20 @@
} else {
((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->ptr = mysqli_resource;
}
+
}
/* }}} */
+
+/* {{{ 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)
Modified: php/php-src/branches/PHP_5_2/ext/mysqli/mysqli_nonapi.c
===================================================================
--- php/php-src/branches/PHP_5_2/ext/mysqli/mysqli_nonapi.c 2010-01-25 13:22:58 UTC (rev 293975)
+++ php/php-src/branches/PHP_5_2/ext/mysqli/mysqli_nonapi.c 2010-01-25 13:23:32 UTC (rev 293976)
@@ -40,8 +40,15 @@
unsigned int hostname_len = 0, username_len = 0, passwd_len = 0, dbname_len = 0, socket_len = 0;
long port=0;
+ if ((MYSQL_VERSION_ID / 100) != (mysql_get_client_version() / 100)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ "Headers and client library minor version mismatch. Headers:%d Library:%ld",
+ MYSQL_VERSION_ID, mysql_get_client_version());
+ }
+
if (getThis() && !ZEND_NUM_ARGS()) {
- RETURN_NULL();
+ php_mysqli_init(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ return;
}
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ssssls", &hostname, &hostname_len, &username, &username_len,
Modified: php/php-src/branches/PHP_5_2/ext/mysqli/php_mysqli.h
===================================================================
--- php/php-src/branches/PHP_5_2/ext/mysqli/php_mysqli.h 2010-01-25 13:22:58 UTC (rev 293975)
+++ php/php-src/branches/PHP_5_2/ext/mysqli/php_mysqli.h 2010-01-25 13:23:32 UTC (rev 293976)
@@ -312,6 +312,8 @@
PHP_MYSQLI_API void mysqli_register_result(zval *return_value, void *result TSRMLS_DC);
PHP_MYSQLI_API void php_mysqli_set_error(long mysql_errno, char *mysql_err TSRMLS_DC);
+void php_mysqli_init(INTERNAL_FUNCTION_PARAMETERS);
+
PHP_MINIT_FUNCTION(mysqli);
PHP_MSHUTDOWN_FUNCTION(mysqli);
PHP_RINIT_FUNCTION(mysqli);
Added: php/php-src/branches/PHP_5_2/ext/mysqli/tests/bug50772.phpt
===================================================================
--- php/php-src/branches/PHP_5_2/ext/mysqli/tests/bug50772.phpt (rev 0)
+++ php/php-src/branches/PHP_5_2/ext/mysqli/tests/bug50772.phpt 2010-01-25 13:23:32 UTC (rev 293976)
@@ -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
Modified: php/php-src/branches/PHP_5_2/ext/mysqli/tests/connect.inc
===================================================================
--- php/php-src/branches/PHP_5_2/ext/mysqli/tests/connect.inc 2010-01-25 13:22:58 UTC (rev 293975)
+++ php/php-src/branches/PHP_5_2/ext/mysqli/tests/connect.inc 2010-01-25 13:23:32 UTC (rev 293976)
@@ -7,7 +7,7 @@
if (!$driver->embedded) {
$host = "localhost";
$user = "root";
- $passwd = "";
+ $passwd = "root";
} else {
$path = dirname(__FILE__);
$host = ":embedded";
Modified: php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_api.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_api.c 2010-01-25 13:22:58 UTC (rev 293975)
+++ php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_api.c 2010-01-25 13:23:32 UTC (rev 293976)
@@ -1333,9 +1333,9 @@
}
/* }}} */
-/* {{{ 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 @@
}
/* }}} */
+
+/* {{{ 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)
Modified: php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_nonapi.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_nonapi.c 2010-01-25 13:22:58 UTC (rev 293975)
+++ php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_nonapi.c 2010-01-25 13:23:32 UTC (rev 293976)
@@ -80,7 +80,8 @@
#endif
if (getThis() && !ZEND_NUM_ARGS() && in_ctor) {
- RETURN_NULL();
+ php_mysqli_init(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ return;
}
hostname = username = dbname = passwd = socket = NULL;
Modified: php/php-src/branches/PHP_5_3/ext/mysqli/php_mysqli_structs.h
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqli/php_mysqli_structs.h 2010-01-25 13:22:58 UTC (rev 293975)
+++ php/php-src/branches/PHP_5_3/ext/mysqli/php_mysqli_structs.h 2010-01-25 13:23:32 UTC (rev 293976)
@@ -338,7 +338,9 @@
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;
long num_links;
Added: php/php-src/branches/PHP_5_3/ext/mysqli/tests/bug50772.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqli/tests/bug50772.phpt (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/mysqli/tests/bug50772.phpt 2010-01-25 13:23:32 UTC (rev 293976)
@@ -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
Modified: php/php-src/trunk/ext/mysqli/mysqli_api.c
===================================================================
--- php/php-src/trunk/ext/mysqli/mysqli_api.c 2010-01-25 13:22:58 UTC (rev 293975)
+++ php/php-src/trunk/ext/mysqli/mysqli_api.c 2010-01-25 13:23:32 UTC (rev 293976)
@@ -1381,9 +1381,9 @@
}
/* }}} */
-/* {{{ proto resource mysqli_init(void) U
- 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;
@@ -1420,6 +1420,16 @@
}
/* }}} */
+
+/* {{{ proto resource mysqli_init(void) U
+ 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) U
Get the ID generated from the previous INSERT operation */
PHP_FUNCTION(mysqli_insert_id)
Modified: php/php-src/trunk/ext/mysqli/mysqli_nonapi.c
===================================================================
--- php/php-src/trunk/ext/mysqli/mysqli_nonapi.c 2010-01-25 13:22:58 UTC (rev 293975)
+++ php/php-src/trunk/ext/mysqli/mysqli_nonapi.c 2010-01-25 13:23:32 UTC (rev 293976)
@@ -75,7 +75,8 @@
#endif
if (getThis() && !ZEND_NUM_ARGS() && in_ctor) {
- RETURN_NULL();
+ php_mysqli_init(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ return;
}
hostname = username = dbname = passwd = socket = NULL;
Modified: php/php-src/trunk/ext/mysqli/php_mysqli_structs.h
===================================================================
--- php/php-src/trunk/ext/mysqli/php_mysqli_structs.h 2010-01-25 13:22:58 UTC (rev 293975)
+++ php/php-src/trunk/ext/mysqli/php_mysqli_structs.h 2010-01-25 13:23:32 UTC (rev 293976)
@@ -228,7 +228,9 @@
extern void php_mysqli_close(MY_MYSQL * mysql, int close_type TSRMLS_DC);
+extern void php_mysqli_init(INTERNAL_FUNCTION_PARAMETERS);
+
#ifdef HAVE_SPL
extern PHPAPI zend_class_entry *spl_ce_RuntimeException;
#endif
Added: php/php-src/trunk/ext/mysqli/tests/bug50772.phpt
===================================================================
--- php/php-src/trunk/ext/mysqli/tests/bug50772.phpt (rev 0)
+++ php/php-src/trunk/ext/mysqli/tests/bug50772.phpt 2010-01-25 13:23:32 UTC (rev 293976)
@@ -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
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php