Fatal error: Uncaught mysqli_sql_exception
A MySQLi query or connection failed; since PHP 8.1 MySQLi throws exceptions by default.
Uncaught mysqli_sql_exception 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 not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in PHP
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 14 Oct 2026