"No database connection" error in ProcessWire database component
0 reputation · 15 Sept 2021, 04:01 UTC
0 reputation · 15 Sept 2021, 04:01 UTC
A ProcessWire installation that functions correctly in a local development environment is triggering a fatal "No database connection" error immediately upon deployment to a production server. The application halts execution, preventing access to both the front-end and the admin interface.
The production environment utilizes a remote database server, whereas the local environment relies on a local MySQL instance. The config.php file has been updated to reflect the production host, username, and password. However, the generic nature of the error message obscures whether the failure stems from a network timeout, incorrect credentials, or a missing PHP PDO driver on the production host.
Given that ProcessWire does not provide a fallback UI for database failures, determining the specific cause of the PDO connection collapse is difficult without modifying the core error handling.
34775 reputation · 15 Sept 2021, 05:00 UTC
To distinguish a DNS/network failure from an authentication error, temporarily wrap ProcessWire’s PDO connection in a try/catch block that logs the PDOException details before re‑throwing or displaying a debug message.
The generic “No database connection” fatal error is thrown when the PDO constructor fails; the underlying PDOException contains the SQLSTATE code and message that tell you whether the problem is a connection‑refused/DNS issue (e.g., SQLSTATE[HY000][2002]) or bad credentials (SQLSTATE[28000][1045]).
wire/core/ProcessWire.php (or the database init in site/config.php).pdo_mysql (often bundled as php‑pdo_mysql or enabled via extension=pdo_mysql).site/config.php.$db = new PDO(...); or within wire/core/ProcessWire.php).try { $db = new PDO($dsn, $user, $pass, $options); } catch (PDOException $e) { // Log details – adjust path as needed error_log('ProcessWire PDO error: '.$e->getMessage().' (SQLSTATE: '.$e->getCode().')'); // Optionally output for debugging (remove in production) echo 'PDO error: '.$e->getMessage().' (SQLSTATE: '.$e->getCode().')'; throw $e; // re‑throw to keep original fatal behaviour if desired }
- Reload the site; check the PHP error log (or the temporary output) for the SQLSTATE and message.
- Interpret the code:
2002→ connection refused/DNS;1045→ bad username/password; other codes point to SSL or server version issues.- Once the cause is identified, revert the try/catch changes (or keep logging only) to avoid exposing credentials.
Verifying the PDO driver
php -m | grep pdo_mysql on the production host; you should see pdo_mysql in the list.phpinfo() page and confirm the PDO section shows PDO drivers => mysql.php.ini (extension=pdo_mysql) and that the MySQL client library (mysqlnd) version is compatible with the remote server (run php -r "echo phpversion('pdo_mysql');" to see the driver version).Missing diagnostic detail: Can you confirm whether the production host can reach the remote MySQL server on port 3306 (e.g., via telnet 3306 or nc -zv 3306)? If the host cannot reach the server, the issue is network/DNS‑related; if it can, focus on credentials or driver compatibility.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 15 Sept 2021, 08:44 UTC
ProcessWire’s fatal "No database connection" comes from a failed PDO constructor. If the web‑server’s PHP SAPI lacks pdo_mysql, the constructor throws before ProcessWire can expose the real SQLSTATE. The CLI may report the driver as available, but the web SAPI can be configured differently.
php -m | grep -i pdo_mysql or create a tiny PHP file with and load it in a browser.PDO::getAvailableDrivers() when executed via the web SAPI.php.ini (or php-fpm.d/*.conf) and reload the server.Once the driver is confirmed, you can safely attribute the failure to DNS, credentials, or network issues rather than a missing PDO extension.