phacility/phabricator · error · Exception

About to call new %s, but the PHP MySQLi extension is not av

Error message

About to call new %s, but the PHP MySQLi extension is not available!

What it means

AphrontMySQLiDatabaseConnection::connect() requires ext/mysqli and checks class_exists('mysqli') up front so the failure is explicit instead of a fatal about an undefined class. mysqli ships with PHP but must still be compiled in or loaded as a package/extension; a runtime without it cannot talk to MySQL at all. This check fires before any connection attempt is made.

Source

Thrown at src/infrastructure/storage/connection/mysql/AphrontMySQLiDatabaseConnection.php:37

  public function getInsertID() {
    return $this->requireConnection()->insert_id;
  }

  public function getAffectedRows() {
    return $this->requireConnection()->affected_rows;
  }

  protected function closeConnection() {
    if ($this->connectionOpen) {
      $this->requireConnection()->close();
      $this->connectionOpen = false;
    }
  }

  protected function connect() {
    if (!class_exists('mysqli', false)) {
      throw new Exception(pht(
        'About to call new %s, but the PHP MySQLi extension is not available!',
        'mysqli()'));
    }

    $user = $this->getConfiguration('user');
    $host = $this->getConfiguration('host');
    $port = $this->getConfiguration('port');
    $database = $this->getConfiguration('database');

    $pass = $this->getConfiguration('pass');
    if ($pass instanceof PhutilOpaqueEnvelope) {
      $pass = $pass->openEnvelope();
    }

    // If the host is "localhost", the port is ignored and mysqli attempts to
    // connect over a socket.
    if ($port) {
      if ($host === 'localhost' || $host === null) {

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Install the extension: apt install php-mysqli (or docker-php-ext-install mysqli in official images), or rebuild PHP with --with-mysqli
  2. Enable it in the php.ini actually loaded by the runtime you use, then restart PHP-FPM / re-run the CLI
  3. Verify with php -m | grep mysqli (and php --ini to confirm which ini is loaded) for both web and CLI
  4. Confirm the same runtime selection if cron/daemon contexts fail while web works

Example fix

# before: PHP runtime without mysqli
$ php -r 'var_dump(class_exists("mysqli"));'  // false => connect() throws

# after: install and enable, then verify
$ apt install php-mysqli && systemctl restart php8.2-fpm
$ php -m | grep mysqli
mysqli
Defensive patterns

Strategy: validation

Validate before calling

// Bootstrap check with an actionable message, before any DB work:
if (!class_exists('mysqli', false)) {
  throw new Exception(
    'ext/mysqli is not loaded in this PHP SAPI. '.
    'Install it (apt install php-mysqli / docker-php-ext-install mysqli), '.
    'enable it in the loaded php.ini, and check with: php -m | grep mysqli');
}

Prevention

When it happens

Trigger: Running Phabricator on PHP built without mysqli (--disable-mysqli or a minimal compile); slim Docker images (bare php:cli) that exclude extensions; extension installed but not enabled in the CLI/FPM php.ini being used; wrong php.ini loaded after an upgrade.

Common situations: Custom-compiled PHP for performance; minimal container images; distro split packages (php-mysqli not installed); the web SAPI has mysqli but the CLI used for bin/storage does not, or the reverse.

Related errors


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/7b08e008888a5b23. Report an issue: GitHub.