Fatal error: Uncaught mysqli_sql_exception
A MySQLi query or connection failed; since PHP 8.1 MySQLi throws exceptions by default.
Seen on:
PHP
Meaning
PHP 8.1 changed the default mysqli error mode to throw mysqli_sql_exception. Code that checked if (!$result) now gets an uncaught exception instead. The message after the class name is the real MySQL error.
Common causes
- SQL error (syntax, unknown column, duplicate key)
- Connection failure
- Old code written for silent errors running on PHP 8.1+
⚡ Quick fix
- Read the MySQL message/code inside the exception
- Wrap queries in try/catch
- Use prepared statements to avoid quoting errors
Detailed fix by platform
PHP
try { $stmt->execute(); } catch (mysqli_sql_exception $e) { error_log($e->getMessage()); }
How to diagnose
- Message — What MySQL error follows the class name?
- Version — Upgraded to PHP 8.1 recently?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026