Skip to content

Commit

Permalink
MFH Fix #45940 MySQLI OO does not populate connect_error property on …
Browse files Browse the repository at this point in the history
…failed

    connect
  • Loading branch information
johannes committed Jan 12, 2009
1 parent 68ecbd7 commit 74cfc5f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ PHP NEWS
(Scott)
- Fixed bug #45989 (json_decode() doesn't return NULL on certain invalid
strings). (magicaltux, Scott)
- Fixed bug #45940 (MySQLI OO does not populate connect_error property on
failed connect). (Johannes)
- Fixed bug #45820 (Allow empty keys in ArrayObject). (Etienne)
- Fixed bug #45791 (json_decode() doesn't convert 0e0 to a double). (Scott)

Expand Down
8 changes: 0 additions & 8 deletions ext/mysqli/mysqli.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,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 */
Expand Down
12 changes: 8 additions & 4 deletions ext/mysqli/mysqli_prop.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "php_mysqli_structs.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; \
Expand Down Expand Up @@ -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)
{
MAKE_STD_ZVAL(*retval);
CHECK_STATUS(MYSQLI_STATUS_INITIALIZED);
ZVAL_LONG(*retval, (long)MyG(error_no));
return SUCCESS;
}
Expand All @@ -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)
{
MAKE_STD_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;
}
/* }}} */
Expand All @@ -158,6 +160,8 @@ static int link_affected_rows_read(mysqli_object *obj, zval **retval TSRMLS_DC)

MAKE_STD_ZVAL(*retval);

CHECK_STATUS(MYSQLI_STATUS_INITIALIZED);

mysql = (MY_MYSQL *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;

if (!mysql) {
Expand Down
4 changes: 2 additions & 2 deletions ext/mysqli/tests/mysqli_fetch_lengths_oo.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ array(2) {
}
NULL

Warning: main(): Couldn't fetch mysqli_result in %s on line %d
Warning: main(): Property access is not allowed yet in %s on line %d
NULL
done!
done!
12 changes: 11 additions & 1 deletion ext/mysqli/tests/mysqli_result_references.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,17 @@ array(7) refcount(2){
&long(4) refcount(2)
}
[6]=>
&object(mysqli_result)#2 (0) refcount(2){
&object(mysqli_result)#2 (5) refcount(2){
["current_field"]=>
NULL refcount(1)
["field_count"]=>
NULL refcount(1)
["lengths"]=>
NULL refcount(1)
["num_rows"]=>
NULL refcount(1)
["type"]=>
NULL refcount(1)
}
}
array(1) refcount(2){
Expand Down

0 comments on commit 74cfc5f

Please sign in to comment.