PHP: Hypertext Preprocessor (original) (raw)

mysqli_driver::$report_mode

mysqli_report

(PHP 5, PHP 7, PHP 8)

mysqli_driver::$report_mode -- mysqli_report — Sets mysqli error reporting mode

Description

Object-oriented style

Procedural style

As of PHP 8.1.0, the default setting is MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT. Previously, it was [MYSQLI_REPORT_OFF](mysqli.constants.php#constant.mysqli-report-off).

Return Values

Always returns [true](reserved.constants.php#constant.true).

Changelog

Version Description
8.1.0 The default value is now MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT. Previously, it was MYSQLI_REPORT_OFF.

Examples

Example #1 Object-oriented style

`<?php/* activate reporting */
$driver = new mysqli_driver();
$driver->report_mode = MYSQLI_REPORT_ALL;

try {

/* if the connection fails, a mysqli_sql_exception will be thrown /
$mysqli = new mysqli("localhost", "my_user", "my_password", "my_db");/
this query should report an error / result=result = result=mysqli->query("SELECT Name FROM Nonexistingtable WHERE population > 50000");/ this query should report a bad index if the column population doesn't have an index */ result=result = result=mysqli->query("SELECT Name FROM City WHERE population > 50000");
} catch (mysqli_sql_exception $e) {
error_log($e->__toString());
}`

Example #2 Procedural style

`<?php/* activate reporting */
mysqli_report(MYSQLI_REPORT_ALL);

try {

/* if the connection fails, a mysqli_sql_exception will be thrown /
$link = mysqli_connect("localhost", "my_user", "my_password", "my_db");/
this query should report an error / result=mysqliquery(result = mysqli_query(result=mysqliquery(link, "SELECT Name FROM Nonexistingtable WHERE population > 50000");/ this query should report a bad index if the column population doesn't have an index */ result=mysqliquery(result = mysqli_query(result=mysqliquery(link, "SELECT Name FROM City WHERE population > 50000");
} catch (mysqli_sql_exception $e) {
error_log($e->__toString());
}`

Example #3 Error reporting except bad index errors

`<?php/* activate reporting */
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

try {

/* if the connection fails, a mysqli_sql_exception will be thrown /
$mysqli = new mysqli("localhost", "my_user", "my_password", "my_db");/
this query should report an error / result=result = result=mysqli->query("SELECT Name FROM Nonexistingtable WHERE population > 50000");/ this WILL NOT report any errors even if index is not available */ result=result = result=mysqli->query("SELECT Name FROM City WHERE population > 50000");
} catch (mysqli_sql_exception $e) {
error_log($e->__toString());
}`

See Also

Found A Problem?

nineoclick (atsymbol) gmail (dot) com

7 years ago

`Seems not clear but flags could be combined, as per other flags.
For example:

report_mode = MYSQLI_REPORT_ALL & ~MYSQLI_REPORT_INDEX;?>

`

theking2 at king dot ma

1 month ago

`Seems not clear but flags could be combined, as per other flags.
For example:

report_mode = MYSQLI_REPORT_ALL | ~MYSQLI_REPORT_INDEX;?>

The other note is plainly wrong

`

theking2 at king dot ma

1 month ago

`Example #1 will now report a depricated warning:

"The mysqli_driver class is an instance of the monostate pattern, i.e. there is only one driver which can be accessed though an arbitrary amount of mysqli_driver instances."

To set the error mode of the mysql driver do use

`