1
0
mirror of https://github.com/php/php-src.git synced 2026-03-30 12:13:02 +02:00

Merge branch 'PHP-7.4' into PHP-8.0

* PHP-7.4:
  Fixed error reporting in mysqli_stmt::__construct
This commit is contained in:
Nikita Popov
2020-11-25 16:29:00 +01:00
2 changed files with 22 additions and 9 deletions

View File

@@ -988,28 +988,32 @@ PHP_METHOD(mysqli_stmt, __construct)
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|s!", &mysql_link, mysqli_link_class_entry, &statement, &statement_len) == FAILURE) {
RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
stmt = (MY_STMT *) ecalloc(1, sizeof(MY_STMT));
stmt->stmt = mysql_stmt_init(mysql->mysql);
if (stmt->stmt && statement) {
mysql_stmt_prepare(stmt->stmt, (char *)statement, statement_len);
}
if (!stmt->stmt) {
if (!(stmt->stmt = mysql_stmt_init(mysql->mysql))) {
efree(stmt);
RETURN_FALSE;
}
#ifndef MYSQLI_USE_MYSQLND
ZVAL_COPY(&stmt->link_handle, mysql_link);
#endif
mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
mysqli_resource->ptr = (void *)stmt;
mysqli_resource->status = (ZEND_NUM_ARGS() == 1) ? MYSQLI_STATUS_INITIALIZED : MYSQLI_STATUS_VALID;
mysqli_resource->status = MYSQLI_STATUS_INITIALIZED;
MYSQLI_REGISTER_RESOURCE_EX(mysqli_resource, getThis());
if (statement) {
if(mysql_stmt_prepare(stmt->stmt, statement, statement_len)) {
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
RETURN_FALSE;
}
mysqli_resource->status = MYSQLI_STATUS_VALID;
}
}
PHP_METHOD(mysqli_result, __construct)

View File

@@ -16,9 +16,18 @@ require_once('skipifconnectfailure.inc');
$stmt->bind_result($foo);
$stmt->fetch();
$stmt->close();
$mysql->close();
var_dump($foo);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
try {
// an exception should be thrown from prepare (i.e. constructor) not from execute
$stmt = new mysqli_stmt($mysql, "SELECT invalid FROM DUAL");
} catch(mysqli_sql_exception $e) {
echo $e->getMessage()."\n";
}
$mysql->close();
?>
--EXPECT--
string(3) "foo"
Unknown column 'invalid' in 'field list'