summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Hristov <andrey@php.net>2010-01-25 13:23:32 +0000
committerAndrey Hristov <andrey@php.net>2010-01-25 13:23:32 +0000
commitfbd7db1f5089eb8a8184afe7af957fd74f7c4d71 (patch)
treebaa81ed4ae01d6fe89e4cac3f03c2bdae4b39b57
parentc5435361ba2ee4a49423782ab8aea7dd9c4744e1 (diff)
downloadphp-git-fbd7db1f5089eb8a8184afe7af957fd74f7c4d71.tar.gz
Fix for bug#50772
mysqli constructor without parameters does not return a working mysqli object
-rw-r--r--NEWS2
-rw-r--r--ext/mysqli/mysqli_api.c17
-rw-r--r--ext/mysqli/mysqli_nonapi.c9
-rw-r--r--ext/mysqli/php_mysqli.h2
-rw-r--r--ext/mysqli/tests/bug50772.phpt36
-rw-r--r--ext/mysqli/tests/connect.inc2
6 files changed, 63 insertions, 5 deletions
diff --git a/NEWS b/NEWS
index 2f8ea8700c..2681a498f0 100644
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,8 @@ PHP NEWS
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)
diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c
index 969a3b011e..3625cb8115 100644
--- a/ext/mysqli/mysqli_api.c
+++ b/ext/mysqli/mysqli_api.c
@@ -1094,9 +1094,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;
@@ -1121,9 +1121,20 @@ PHP_FUNCTION(mysqli_init)
} 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)
diff --git a/ext/mysqli/mysqli_nonapi.c b/ext/mysqli/mysqli_nonapi.c
index 400e0f20f2..1a468e36e0 100644
--- a/ext/mysqli/mysqli_nonapi.c
+++ b/ext/mysqli/mysqli_nonapi.c
@@ -40,8 +40,15 @@ PHP_FUNCTION(mysqli_connect)
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,
diff --git a/ext/mysqli/php_mysqli.h b/ext/mysqli/php_mysqli.h
index 079c0eee8f..fe5da2ee7c 100644
--- a/ext/mysqli/php_mysqli.h
+++ b/ext/mysqli/php_mysqli.h
@@ -312,6 +312,8 @@ PHP_MYSQLI_API void mysqli_register_stmt(zval *return_value, void *stmt TSRMLS_D
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);
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
diff --git a/ext/mysqli/tests/connect.inc b/ext/mysqli/tests/connect.inc
index ea24ff89ae..b770a1d3f3 100644
--- a/ext/mysqli/tests/connect.inc
+++ b/ext/mysqli/tests/connect.inc
@@ -7,7 +7,7 @@
if (!$driver->embedded) {
$host = "localhost";
$user = "root";
- $passwd = "";
+ $passwd = "root";
} else {
$path = dirname(__FILE__);
$host = ":embedded";