]> granicus.if.org Git - php/commitdiff
MFH: Fix #45940 MySQLI OO does not populate connect_error property on failed connect
authorJohannes Schlüter <johannes@php.net>
Tue, 17 Feb 2009 10:40:18 +0000 (10:40 +0000)
committerJohannes Schlüter <johannes@php.net>
Tue, 17 Feb 2009 10:40:18 +0000 (10:40 +0000)
NEWS
ext/mysqli/mysqli.c
ext/mysqli/mysqli_prop.c
ext/mysqli/tests/bug45940.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index e390f241e3c250829dbdcbe1c9da4a925a842aee..9f92210882ab1c311c4af448ffeae0217492435c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,8 @@ PHP                                                                        NEWS
 ?? Feb 2009, PHP 5.2.9
 - Fixed bug #47399 (mb_check_encoding() returns true for some illegal SJIS
   characters). (for-bugs at hnw dot jp, Moriyoshi)
+- Fixed bug #45940 (MySQLI OO does not populate connect_error property on
+  failed connect). (Johannes)
 - Fixed bug #45923 (mb_st[r]ripos() offset not handled correctly). (Moriyoshi)
 - Fixed bug #43841 (mb_strrpos() offset is byte count for negative values).
   (Moriyoshi)
index 2f3d56a12eb8aceae4922a5f4ca0d9bce54f52db..94f8cad0fedb57906777bd3cbb21c11a2e591844 100644 (file)
@@ -254,13 +254,6 @@ zval *mysqli_read_property(zval *object, zval *member, int type TSRMLS_DC)
        }
 
        if (ret == SUCCESS) {
-               if (strcmp(obj->zo.ce->name, "mysqli_driver") &&
-            (!obj->ptr || ((MYSQLI_RESOURCE *)(obj->ptr))->status < MYSQLI_STATUS_INITIALIZED)) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't fetch %s", obj->zo.ce->name );
-                       retval = EG(uninitialized_zval_ptr);
-                       return(retval);
-               }
-
                ret = hnd->read_func(obj, &retval TSRMLS_CC);
                if (ret == SUCCESS) {
                        /* ensure we're creating a temporary variable */
index e5c84dc4e054d7cef928674c9a5c01c39bd3f5d3..ff0a7cb1d8d1deb0cbaa8e2a72b33da59400c15e 100644 (file)
@@ -30,7 +30,7 @@
 #include "php_mysqli.h"
 
 #define CHECK_STATUS(value) \
-       if (((MYSQLI_RESOURCE *)obj->ptr)->status < value ) { \
+       if (!obj->ptr || ((MYSQLI_RESOURCE *)obj->ptr)->status < value ) { \
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Property access is not allowed yet"); \
                ZVAL_NULL(*retval); \
                return SUCCESS; \
@@ -134,7 +134,6 @@ static int link_client_info_read(mysqli_object *obj, zval **retval TSRMLS_DC)
 static int link_connect_errno_read(mysqli_object *obj, zval **retval TSRMLS_DC)
 {
        ALLOC_ZVAL(*retval);
-       CHECK_STATUS(MYSQLI_STATUS_INITIALIZED);
        ZVAL_LONG(*retval, (long)MyG(error_no));
        return SUCCESS;
 }
@@ -144,8 +143,11 @@ static int link_connect_errno_read(mysqli_object *obj, zval **retval TSRMLS_DC)
 static int link_connect_error_read(mysqli_object *obj, zval **retval TSRMLS_DC)
 {
        ALLOC_ZVAL(*retval);
-       CHECK_STATUS(MYSQLI_STATUS_INITIALIZED);
-       ZVAL_STRING(*retval, MyG(error_msg), 1);
+       if (MyG(error_msg)) {
+               ZVAL_STRING(*retval, MyG(error_msg), 1);
+       } else {
+               ZVAL_NULL(*retval);
+       }
        return SUCCESS;
 }
 /* }}} */
diff --git a/ext/mysqli/tests/bug45940.phpt b/ext/mysqli/tests/bug45940.phpt
new file mode 100644 (file)
index 0000000..5a8b6bb
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Bug #45940 MySQLI OO does not populate connect_error property on failed connect
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+include "connect.inc";
+
+//a forced username/password mismatch
+$dbo = @new mysqli($host, 'hopenotexist', 'andifheexistshehasanotherpassword', 'my_db');
+
+var_dump($dbo->connect_error);
+var_dump(mysqli_connect_error());
+?>
+--EXPECTF--
+string(71) "Access denied for user 'hopenotexist'@'localhost' (using password: YES)"
+string(71) "Access denied for user 'hopenotexist'@'localhost' (using password: YES)"
+