Hi to all,
this is my environment:
OS: Ubuntu 22.04
PHP version; 8.2
PHP Repository: ondrej (deb https://ppa.launchpadcontent.net/ondrej/php/ubuntu/ jammy main)
Webserver: Nginx
DB: Mariadb 10.10.6
I can connect to Mariadb and execute the query, but if a query returns an error, php stops to continue the code and returns a "Fatal error". My code to connect to Mariadb is:
mysqli_report(MYSQLI_REPORT_OFF);
$link = mysqli_connect($db_host, "$db_username", "$db_pwd", "$db_name", $db_port, "$db_socket");
and the connection is OK, no problem!
As I want to handle the errors, I use the following code:
$results=mysqli_query($link, $query);
$num_rows=mysqli_num_rows($results)
if(!is_numeric($num_rows) OR $num_rows<0) {
// Return an error message and exit
}
// If there is not error the php scrip continue...
Now the problem is that the function mysqli_num_rows($results) cause a Fatal error and no other codes is executed.
Fatal error: Uncaught TypeError: mysqli_num_rows(): Argument #1 ($result) must be of type mysqli_result, bool given in ....
TypeError: mysqli_num_rows(): Argument #1 ($result) must be of type mysqli_result, bool given in ...
I know that from PHP 8.1 MySQLi's default error mode is changed from MYSQLI_REPORT_OFF to MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT and therefore, before to connect to Mariadb, I use the command:
mysqli_report(MYSQLI_REPORT_OFF)
but it doesn't work. Why?
Could someone help me, please?
Thank you very much!