I ran into this Problem with the PHP Data Object.
I cannot connect to my Database. First here is my PHP Script:
<?php
$serverName = "127.0.0.1";
$port = "3306";
$dbName = "callitTime";
$userName = "root";
$password = "superstrongPassword";
try {
$db = new PDO("mysql:host=$serverName;dbname=$dbName;port=$port;",
$userName, $password);
} catch (PDOException $pdoE) {
echo 'An Error occurred: ' . $pdoE->getMessage();
}
?>
I am using:
PHP 7.1.16
Nginx 1.13.12-1
MySQL 8.0.11-1debian9
All as Docker Containers.
A phpinfo() tells me that PDO Drivers are loaded as follows:
PDO Drivers:
sqlite
mysql
Driver Versions:
mysqlnd 5.0.12-dev
SQLite Library 3.15.1
I get the Error:
An Error occurred: SQLSTATE[HY000] [2002] Connection refused
I can connect to the same Database via Phpstorm with the same Password and Username.