{"record":{"id":"7b08e008888a5b23","repo":"phacility/phabricator","slug":"about-to-call-new-s-but-the-php-mysqli-extension","errorCode":null,"errorMessage":"About to call new %s, but the PHP MySQLi extension is not available!","messagePattern":"About to call new (.+?), but the PHP MySQLi extension is not available!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/infrastructure/storage/connection/mysql/AphrontMySQLiDatabaseConnection.php","lineNumber":37,"sourceCode":"\n  public function getInsertID() {\n    return $this->requireConnection()->insert_id;\n  }\n\n  public function getAffectedRows() {\n    return $this->requireConnection()->affected_rows;\n  }\n\n  protected function closeConnection() {\n    if ($this->connectionOpen) {\n      $this->requireConnection()->close();\n      $this->connectionOpen = false;\n    }\n  }\n\n  protected function connect() {\n    if (!class_exists('mysqli', false)) {\n      throw new Exception(pht(\n        'About to call new %s, but the PHP MySQLi extension is not available!',\n        'mysqli()'));\n    }\n\n    $user = $this->getConfiguration('user');\n    $host = $this->getConfiguration('host');\n    $port = $this->getConfiguration('port');\n    $database = $this->getConfiguration('database');\n\n    $pass = $this->getConfiguration('pass');\n    if ($pass instanceof PhutilOpaqueEnvelope) {\n      $pass = $pass->openEnvelope();\n    }\n\n    // If the host is \"localhost\", the port is ignored and mysqli attempts to\n    // connect over a socket.\n    if ($port) {\n      if ($host === 'localhost' || $host === null) {","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/infrastructure/storage/connection/mysql/AphrontMySQLiDatabaseConnection.php#L19-L55","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Install the extension: apt install php-mysqli (or docker-php-ext-install mysqli in official images), or rebuild PHP with --with-mysqli","Enable it in the php.ini actually loaded by the runtime you use, then restart PHP-FPM / re-run the CLI","Verify with php -m | grep mysqli (and php --ini to confirm which ini is loaded) for both web and CLI","Confirm the same runtime selection if cron/daemon contexts fail while web works"],"exampleFix":"# before: PHP runtime without mysqli\n$ php -r 'var_dump(class_exists(\"mysqli\"));'  // false => connect() throws\n\n# after: install and enable, then verify\n$ apt install php-mysqli && systemctl restart php8.2-fpm\n$ php -m | grep mysqli\nmysqli","handlingStrategy":"validation","validationCode":"// Bootstrap check with an actionable message, before any DB work:\nif (!class_exists('mysqli', false)) {\n  throw new Exception(\n    'ext/mysqli is not loaded in this PHP SAPI. '.\n    'Install it (apt install php-mysqli / docker-php-ext-install mysqli), '.\n    'enable it in the loaded php.ini, and check with: php -m | grep mysqli');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Include php-mysqli (or compile with --with-mysqli) in every runtime image and package set, web and CLI alike","Verify with php -m | grep mysqli after provisioning and after PHP upgrades","Confirm php --ini to make sure the CLI loads the same extensions as FPM"],"tags":["php","extension","mysqli","runtime-environment","bootstrap"],"backgroundTag":"missing-php-extension","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}