From: Johannes Schlüter Date: Tue, 17 Feb 2009 10:40:18 +0000 (+0000) Subject: MFH: Fix #45940 MySQLI OO does not populate connect_error property on failed connect X-Git-Tag: php-5.2.9RC3~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7d8db13f399323e97926e464151885a42732b24a;p=php MFH: Fix #45940 MySQLI OO does not populate connect_error property on failed connect --- diff --git a/NEWS b/NEWS index e390f241e3..9f92210882 100644 --- 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) diff --git a/ext/mysqli/mysqli.c b/ext/mysqli/mysqli.c index 2f3d56a12e..94f8cad0fe 100644 --- a/ext/mysqli/mysqli.c +++ b/ext/mysqli/mysqli.c @@ -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 */ diff --git a/ext/mysqli/mysqli_prop.c b/ext/mysqli/mysqli_prop.c index e5c84dc4e0..ff0a7cb1d8 100644 --- a/ext/mysqli/mysqli_prop.c +++ b/ext/mysqli/mysqli_prop.c @@ -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 index 0000000000..5a8b6bb048 --- /dev/null +++ b/ext/mysqli/tests/bug45940.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #45940 MySQLI OO does not populate connect_error property on failed connect +--SKIPIF-- + +--FILE-- +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)" +