I have the following settings in docker-compose.yml
mysql:
image: mysql:latest
ports:
- "3306"
volumes:
- /var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: project
MYSQL_USER: project
MYSQL_PASSWORD: project
In my index.php, I want to connect to my database container, however, I'm not sure what to type in host=localhost,
the following code doesn't work
<?php
$db = new PDO('mysql:host=localhost;dbname=project;charset=utf8mb4', 'project', 'secret');
It says
Fatal error: Uncaught PDOException: could not find driver in /code/index.php:2 Stack trace: #0 /code/index.php(2): PDO->__construct('mysql:host=loca...', 'project', 'secret') #1 {main} thrown in /code/index.php on line 2
Thanks