?? 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)
}
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 */
#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; \
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;
}
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;
}
/* }}} */
--- /dev/null
+--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)"
+