Skip to content

mysqli_query throws warning despite using silenced error mode #9842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
1 change: 1 addition & 0 deletions ext/mysqli/mysqli.c
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,7 @@ PHP_METHOD(mysqli_result, __construct)
}

if (!result) {
MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
RETURN_FALSE;
}

Expand Down
6 changes: 2 additions & 4 deletions ext/mysqli/mysqli_nonapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,7 @@ PHP_FUNCTION(mysqli_query)
break;
}
if (!result) {
php_mysqli_throw_sql_exception((char *)mysql_sqlstate(mysql->mysql), mysql_errno(mysql->mysql),
"%s", mysql_error(mysql->mysql));
MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
RETURN_FALSE;
}

Expand Down Expand Up @@ -935,8 +934,7 @@ PHP_FUNCTION(mysqli_reap_async_query)
}

if (!result) {
php_mysqli_throw_sql_exception((char *)mysql_sqlstate(mysql->mysql), mysql_errno(mysql->mysql),
"%s", mysql_error(mysql->mysql));
MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
RETURN_FALSE;
}

Expand Down
78 changes: 78 additions & 0 deletions ext/mysqli/tests/gh9841.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
--TEST--
Bug GH-9841 (mysqli_query throws warning despite using silenced error mode)
--SKIPIF--
<?php
require_once 'skipif.inc';
require_once 'skipifconnectfailure.inc';
?>
--FILE--
<?php

require_once 'connect.inc';

mysqli_report(MYSQLI_REPORT_OFF);

$mysqli = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);

$mysqli->query("SELECT (
SELECT 1 AS val
UNION ALL
SELECT 2
) FROM dual");

$mysqli->query("SELECT (
SELECT 1 AS val
UNION ALL
SELECT 2
) FROM dual", MYSQLI_ASYNC);
$mysqli->reap_async_query();

$mysqli->real_query("SELECT (
SELECT 1 AS val
UNION ALL
SELECT 2
) FROM dual");
$result = new mysqli_result($mysqli);

// now make sure the errors are thrown when not using silent mode
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

try {
$mysqli->query("SELECT (
SELECT 1 AS val
UNION ALL
SELECT 2
) FROM dual");
} catch (mysqli_sql_exception $e) {
echo $e->getMessage()."\n";
}

$mysqli->query("SELECT (
SELECT 1 AS val
UNION ALL
SELECT 2
) FROM dual", MYSQLI_ASYNC);
try {
$mysqli->reap_async_query();
} catch (mysqli_sql_exception $e) {
echo $e->getMessage()."\n";
}

$mysqli->real_query("SELECT (
SELECT 1 AS val
UNION ALL
SELECT 2
) FROM dual");
try {
$result = new mysqli_result($mysqli);
} catch (mysqli_sql_exception $e) {
echo $e->getMessage()."\n";
}

print "done!";
?>
--EXPECTF--
Subquery returns more than 1 row
Subquery returns more than 1 row
Subquery returns more than 1 row
done!