# Fatal error: Uncaught mysqli_sql_exception

**Code:** `mysqli_sql_exception` · **Category:** PHP · **Seen on:** PHP

A MySQLi query or connection failed; since PHP 8.1 MySQLi throws exceptions by default.

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/php/mysqli-sql-exception)
