SECURITY WARNING: Never run commands you don't understand. Always review code before execution. Use at your own risk.
PHP New Added 26 October 2026

PHP: Fatal error: Uncaught Error: Call to undefined function mysqli_connect()

PHP cannot find the function because the mysqli extension is not loaded in the PHP that ran the script. MySQL itself is not involved yet. Distributions ship extensions as separate packages (php8.3-mysql on Debian and Ubuntu, php-mysqlnd on RHEL), and the CLI and PHP-FPM read different php.ini files, so php -m can list mysqli while the web server still fails. The official Docker php images leave it out until you install it.

Quick fix

Read the commands before running them. Anything that restarts a service, deletes data or changes permissions should be tried on a non-production system first.

Quick fix
# Is mysqli loaded for the CLI, and which php.ini is in use?
php -m | grep -i mysqli
php --ini

# The web server may load a different ini: check a temporary phpinfo() page
# for a "mysqli" section and the "Loaded Configuration File" line

# Debian / Ubuntu (match your PHP version)
sudo apt install php8.3-mysql
sudo systemctl restart php8.3-fpm    # or apache2 when using mod_php

# RHEL / Fedora / Rocky
sudo dnf install php-mysqlnd

# Official Docker php images, in the Dockerfile
# RUN docker-php-ext-install mysqli pdo_mysql

# Windows: uncomment this line in php.ini, then restart the server
# extension=mysqli

How to diagnose PHP errors

PHP errors are dominated by per-request resource limits (memory_limit, max_execution_time) and by autoloading. Class-not-found errors are almost never missing code. They are a namespace that does not match the PSR-4 mapping, or a stale Composer autoload map. Laravel adds a caching layer that produces genuinely confusing errors when configuration is cached with the wrong environment.

If the quick fix above does not resolve it, work through these steps. They apply to this whole class of error, not just to this one message, which is usually what saves the time.

  1. Read the real limits from the running process, not from a config file: php -i | grep -E 'memory_limit|max_execution_time'. CLI and FPM have separate configurations.
  2. Regenerate the autoload map with composer dump-autoload -o before investigating a class-not-found error any further.
  3. For Laravel, clear cached config and routes with php artisan optimize:clear. A config cache built in the wrong environment causes errors that survive every code change.
  4. Enable full error display in development (display_errors=On, error_reporting=E_ALL). The default production settings hide the cause.
  5. For PDO connection refusals, test the same credentials with the database's own CLI client to separate PHP configuration from database access.

Tools worth reaching for

  • php -i
  • composer dump-autoload -o
  • php artisan optimize:clear
  • Xdebug
  • tail -f storage/logs/laravel.log

Authoritative references

Primary documentation for this error, worth reading before applying any fix in production.

php.net

Related PHP errors

See all 20 PHP errors →

Browse other categories

Something missing or wrong?

This entry is maintained by hand. If the fix is out of date, incomplete, or you have a better one, email a correction and it will be reviewed.