Seems not clear but flags *could be combined*, as per other flags.
For example:
<?php
# wannabe noticed about all errors except those about indexes
$driver = new mysqli_driver();
$driver->report_mode = MYSQLI_REPORT_ALL & ~MYSQLI_REPORT_INDEX;
?>
(PHP 5, PHP 7, PHP 8)
mysqli_driver::$report_mode -- mysqli_report — Define el modo de informe de errores de mysqli
Estilo orientado a objetos
Estilo por procedimientos
Según los flags, esto define el modo de informe de errores de mysqli
a excepción, advertencia o ninguno.
Cuando se define como MYSQLI_REPORT_ALL
o MYSQLI_REPORT_INDEX
esto también informará sobre consultas que no utilizan un índice
(o un índice incorrecto).
A partir de PHP 8.1.0, el valor por omisión es MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT
.
Anteriormente, era MYSQLI_REPORT_OFF
.
flags
Nombre | Descripción |
---|---|
MYSQLI_REPORT_OFF |
Desactiva los informes (valor por omisión) |
MYSQLI_REPORT_ERROR |
Informa sobre errores desde llamadas a funciones mysqli |
MYSQLI_REPORT_STRICT |
Lanza una excepción mysqli_sql_exception para errores, en lugar de emitir alertas |
MYSQLI_REPORT_INDEX |
Informa si no se utiliza ningún índice o un índice incorrecto en una consulta |
MYSQLI_REPORT_ALL |
Define todas las opciones (informa sobre todo) |
Versión | Descripción |
---|---|
8.1.0 |
El valor por omisión es ahora MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT .
Anteriormente, era MYSQLI_REPORT_OFF .
|
Ejemplo #1 Estilo orientado a objetos
<?php
/* Activación del informe de errores */
$driver = new mysqli_driver();
$driver->report_mode = MYSQLI_REPORT_ALL;
try {
/* si la conexión falla, se lanzará una mysqli_sql_exception */
$mysqli = new mysqli("localhost", "my_user", "my_password", "my_db");
/* esta consulta debería informar sobre un error */
$result = $mysqli->query("SELECT Name FROM Nonexistingtable WHERE population > 50000");
/* esta consulta debería informar sobre un índice incorrecto, si la columna population no tiene un índice */
$result = $mysqli->query("SELECT Name FROM City WHERE population > 50000");
} catch (mysqli_sql_exception $e) {
error_log($e->__toString());
}
Ejemplo #2 Estilo por procedimientos
<?php
/* Activación del informe de errores */
mysqli_report(MYSQLI_REPORT_ALL);
try {
/* si la conexión falla, se lanzará una excepción mysqli_sql_exception */
$link = mysqli_connect("localhost", "my_user", "my_password", "my_db");
/* esta consulta debería informar sobre un error */
$result = mysqli_query($link, "SELECT Name FROM Nonexistingtable WHERE population > 50000");
/* esta consulta debería informar sobre un índice incorrecto, si la columna population no tiene un índice */
$result = mysqli_query($link, "SELECT Name FROM City WHERE population > 50000");
} catch (mysqli_sql_exception $e) {
error_log($e->__toString());
}
Ejemplo #3 Informe de errores a excepción de errores de índice incorrecto
<?php
/* Activación del informe de errores */
$driver = new mysqli_driver();
$driver->report_mode = MYSQLI_REPORT_ALL;
try {
/* si la conexión falla, se lanzará una mysqli_sql_exception */
$mysqli = new mysqli("localhost", "my_user", "my_password", "my_db");
/* esta consulta debería informar sobre un error */
$result = $mysqli->query("SELECT Name FROM Nonexistingtable WHERE population > 50000");
/* esto NO emitirá un error incluso si no hay ningún índice disponible */
$result = $mysqli->query("SELECT Name FROM City WHERE population > 50000");
} catch (mysqli_sql_exception $e) {
error_log($e->__toString());
}
Seems not clear but flags *could be combined*, as per other flags.
For example:
<?php
# wannabe noticed about all errors except those about indexes
$driver = new mysqli_driver();
$driver->report_mode = MYSQLI_REPORT_ALL & ~MYSQLI_REPORT_INDEX;
?>
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
<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
?>