Ok, so here's the deal: I'm using Docker-Compose to create 3 services: one for the platform, one for db (mysql) and the third for PHPMyAdmin
I'm trying to use mysqli to connect to the database on port 5001.
What’s interesting is that I can connect to the database using SQL Workbench and PHPMyAdmin with the same parameters, but I get an error (seen below) when connecting using PHP MySQLi
Platform:
$db = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT);
The host is 127.0.0.1, the DB_USER is root with its respective password, I've provided a DB_Name and the port is 5001.
My Docker-Compose.yml looks like this:
version: '3.3'
services:
platform:
build: .
ports:
- "5000:80"
links:
- db:mysql
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
ports:
#- "5001:80"
- "5001:3306"
environment:
MYSQL_ROOT_PASSWORD: some_great_password_here
MYSQL_DATABASE: DB_NAME_HERE
MYSQL_USER: USERNAME
MYSQL_PASSWORD: PASSWORD
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- db:mysql
ports:
- 8181:80
environment:
MYSQL_USERNAME: USERNAME
MYSQL_ROOT_PASSWORD: PASSWORD
volumes:
db_data:
For some reason, I keep getting the error:
mysqli::mysqli(): (HY000/2003): Can't connect to MySQL server on '127.0.0.1' (111) in ...
Any tips or a solution would be much appreciated!