Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ PHP NEWS
- MBString:
. Fixed bug GH-17112 (Macro redefinitions). (nielsdos, cmb)

- mysqli:
. Fixed failed assertion when accessing mysqli property after failed
reconnection. (Kamil Tekiela)

- Opcache:
. opcache_get_configuration() properly reports jit_prof_threshold. (cmb)

Expand Down
30 changes: 22 additions & 8 deletions ext/mysqli/mysqli_prop.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,29 @@

#define MYSQLI_GET_MYSQL(statusval) \
MYSQL *p; \
if (!obj->ptr || !(MY_MYSQL *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr) { \
if (!quiet) { \
zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(obj->zo.ce->name)); \
{ \
MYSQLI_RESOURCE *my_res = obj->ptr; \
MY_MYSQL *my_mysql; \
if (!my_res || !(my_mysql = (MY_MYSQL *)my_res->ptr)) { \
if (!quiet) { \
zend_throw_error(NULL, "%s object is already closed", ZSTR_VAL(obj->zo.ce->name)); \
} \
return FAILURE; \
} \
return FAILURE; \
} else { \
CHECK_STATUS(statusval, quiet);\
p = (MYSQL *)((MY_MYSQL *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr)->mysql;\
}
if (my_res->status < statusval ) { \
if (!quiet) { \
zend_throw_error(NULL, "Property access is not allowed yet"); \
} \
return FAILURE; \
} \
p = (MYSQL *)my_mysql->mysql;\
if (!p) { \
if (!quiet) { \
zend_throw_error(NULL, "%s object is not fully initialized", ZSTR_VAL(obj->zo.ce->name)); \
} \
return FAILURE; \
} \
} \

#define MYSQLI_GET_RESULT(statusval) \
MYSQL_RES *p; \
Expand Down
38 changes: 38 additions & 0 deletions ext/mysqli/tests/mysqli_incomplete_initialization2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--TEST--
host_info() dumps with assert after failed reconnect
--EXTENSIONS--
mysqli
--SKIPIF--
<?php
require_once 'skipifconnectfailure.inc';
?>
--FILE--
<?php
include 'connect.inc';

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = mysqli_init();

$mysqli->connect($host, $user, $passwd, $db, $port, $socket);

echo 'Success... ' . $mysqli->host_info . "\n";

try {
$mysqli->connect($host, $user, $passwd, $db.'wrong', $port, $socket);
} catch (mysqli_sql_exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}

try {
echo $mysqli->host_info . "\n";
} catch (Error $e) {
echo "Error: " . $e->getMessage() . "\n";
}

print "done!";
?>
--EXPECTF--
Success... %s via %s
Error: Unknown database 'testwrong'
Error: mysqli object is not fully initialized
done!
Loading