I've seen several other posts with this issue. One in particular is this:
Docker MYSQL '[2002] Connection refused'
I tried to add PMA_HOST: mysql as instructed in the previous question.
Here is my docker-compose.yml file looks like:
version: "3.7" services: www: build: . ports: - "8001:80" volumes: - ./www:/var/www/html/ links: - db networks: - default db: image: mysql:8.0 ports: - "3306:3306" environment: MYSQL_DATABASE: myDb MYSQL_USER: user MYSQL_PASSWORD: test MYSQL_ROOT_PASSWORD: test volumes: - ./dump:/docker-entrypoint-initdb.d networks: - default phpmyadmin: image: phpmyadmin/phpmyadmin links: - db:db ports: - 8000:80 environment: MYSQL_USER: user MYSQL_PASSWORD: test MYSQL_ROOT_PASSWORD: test volumes: persistent: My dockerfile:
FROM php:7.0.30-apache RUN docker-php-ext-install pdo pdo_mysql Using the above, when trying to connect to the database, I get the error:
Conneciton failed: SQLSTATE[HY000] [2002] Connection refused As stated, from the previously asked question, I updated the yml file to include PMA_HOST: mysql under the environment section of the phpmyadmin service. Problem is, when I do that, I can no longer log into the phpmyadmin.
Does anyone see what I am doing wrong and now I can fix it?
*** EDIT ***
Here is my database connection file:
<?php $host = '127.0.0.1'; $dbname = 'myDb'; define ('DB_USER', 'user'); define ('DB_PASSWORD', 'test'); try { $dbc = new PDO("mysql:dbname=$dbname;host=$host", DB_USER, DB_PASSWORD); $dbc->SetAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { echo "Connection failed: " . $e->getMessage() . "<br/>"; } ?>
$host.