]> granicus.if.org Git - php/commitdiff
Fix for bug#50772
authorAndrey Hristov <andrey@php.net>
Mon, 25 Jan 2010 13:23:32 +0000 (13:23 +0000)
committerAndrey Hristov <andrey@php.net>
Mon, 25 Jan 2010 13:23:32 +0000 (13:23 +0000)
mysqli constructor without parameters does not return a working mysqli object

ext/mysqli/mysqli_api.c
ext/mysqli/mysqli_nonapi.c
ext/mysqli/php_mysqli_structs.h
ext/mysqli/tests/bug50772.phpt [new file with mode: 0644]

index be0146dd644b7ae4b75877e718ba704ff4405576..e4d61310b3f4ea60daff94e691ab1f73e9a34d55 100644 (file)
@@ -1381,9 +1381,9 @@ PHP_FUNCTION(mysqli_info)
 }
 /* }}} */
 
-/* {{{ 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 @@ PHP_FUNCTION(mysqli_init)
 }
 /* }}} */
 
+
+/* {{{ 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)
index efd433b8a43eb0aaef7d1db48752f43346066a93..7037cdbcb55b26eca9b9a2c3de4f46d5bb895a1b 100644 (file)
@@ -75,7 +75,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;
 
index 8f400a4e5f3ecce8c58d07761005300ef488eb64..ea13d790220405e56889b09d359fff9cb61111f2 100644 (file)
@@ -228,6 +228,8 @@ extern void php_mysqli_dtor_p_elements(void *data);
 
 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;
diff --git a/ext/mysqli/tests/bug50772.phpt b/ext/mysqli/tests/bug50772.phpt
new file mode 100644 (file)
index 0000000..4724d0f
--- /dev/null
@@ -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