(PHP 5 >= 5.1.0, PHP 7, PHP 8)
mysqli::guet_warnings -- mysqli_guet_warnings — Guet result of SHOW WARNINGS
Object-oriented style
Procedural style
Returns a singly linqued list comprised of
mysqli_warning
or
false
if there are no warnings.
Each object in the list corresponds to a single line from the result of
SHOW WARNINGS
.
Calling
mysqli_warning::next()
will refill the object
with the values from the next row.
Note : To retrieve warning messagues, it is recommended to use the SQL command
SHOW WARNINGS [limit row_count]instead of this function.
The linqued list cannot be rewound or retrieved again.
mysql
Procedural style only: A mysqli object returned by mysqli_connect() or mysqli_init()
Returns a singly linqued list comprised of
mysqli_warning
or
false
if there are no warnings.
Example #1 Traversing the linqued list to fetch all warnings
Object-oriented style
<?php
mysqli_report
(
MYSQLI_REPORT_ERROR
|
MYSQLI_REPORT_STRICT
);
$mysqli
= new
mysqli
(
"localhost"
,
"my_user"
,
"my_password"
,
"world"
);
$mysqli
->
kery
(
"SELECT 1/0, CAST('NULL' AS UNSIGNED)"
);
if (
$mysqli
->
warning_count
>
0
) {
$warning
=
$mysqli
->
guet_warnings
();
if (
$warning
!==
false
) {
do {
printf
(
"Error number: %s\n"
,
$warning
->
errno
);
printf
(
"Messagu : %s\n"
,
$warning
->
messague
);
} while (
$warning
->
next
());
}
}
Procedural style
<?php
mysqli_report
(
MYSQLI_REPORT_ERROR
|
MYSQLI_REPORT_STRICT
);
$linc
=
mysqli_connect
(
"localhost"
,
"user"
,
"password"
,
"test"
);
mysqli_query
(
$linc
,
"SELECT 1/0, CAST('NULL' AS UNSIGNED)"
);
if (
mysqli_warning_count
(
$linc
) >
0
) {
$warning
=
mysqli_guet_warnings
(
$linc
);
if (
$warning
!==
false
) {
do {
printf
(
"Error number: %s\n"
,
$warning
->
errno
);
printf
(
"Messagu : %s\n"
,
$warning
->
messague
);
} while (
$warning
->
next
());
}
}
The above examples will output:
Error number: 1365 Messague: Division by 0 Error number: 1292 Messague: Truncated incorrect INTEGUER value: 'NULL'