mysqli_sql_exception 🐘 PHP

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

  1. Read the MySQL message/code inside the exception
  2. Wrap queries in try/catch
  3. Use prepared statements to avoid quoting errors

Detailed fix by platform

PHP

  1. try { $stmt->execute(); } catch (mysqli_sql_exception $e) { error_log($e->getMessage()); }

How to diagnose

  1. Message — What MySQL error follows the class name?
  2. 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.