I switched to PHP 8.2 a couple weeks ago (from PHP 7.0.something), but I have issues with it thinking every minor error from mysqli is fatal and fails to run the "die" part. This is an except from my MySQL interface class (this is for development use) that I've tried to get to work properly with PHP 8:
public function query($query) {
$result = mysqli_query($this->db_link,$query) or $this->error('Unable to execute query<br/>'.$query);
return $result;
}
public function error($message) {
echo '<div align="center"><span style="font-size:150%;color:#FF0000;>ERROR! </span><span>'.$message.'<br /><br />'.mysqli_errno($this->db_link).': '.mysqli_error($this->db_link).'</span></div>';
}
If I happen to have a typo or other issue in the query, on PHP 7 and pretty much every older version for the past several years, this would correctly jump to the error part whenever there was the slightest issue with the query and tell me what I need to know to fix it.
PHP 8 on the other hand completely ignores the 'OR' part and instead throws "Fatal error: Uncaught mysqli_sql_exception" with a mess of an error message that does not help me much at all since it only has like 4 characters from the query, which really is not enough with dynamically built queries.
In this case I appear to have a typo somewhere in a rather chunky query (since it's dynamically built), but because PHP fails to run the 'OR' part I'm left with this error
Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`0','0','1'' at line 9 in D:\web\testbase\include\mysql.php:53 Stack trace: #0 D:\web\testbase\include\mysql.php(53): mysqli_query(Object(mysqli), 'INSERT\r\n ...') #1 D:\web\testbase\work.php(36): db->query('INSERT\r\n ...') #2 {main} thrown in D:\web\testbase\include\mysql.php on line 53
Does PHP 8 require a completely different format for the 'DO OR DIE' approach or why does it refuse to execute the second half of the statement? (Note: I'm trying to avoid using actual 'DIE' as much as possible)
Also why does PHP go "fatal" here when a MySQL error by no means is fatal to the PHP parser. Sure the query fails, but I write my code to deal with that (or so I thought).