Eu subi uma aplicação PHP com mysql através do docker-compose.yml
:
version: '3'
volumes:
data:
services:
db:
image: mysql:5.6
restart: always
ports:
- '3306:3306'
volumes:
- data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=socialmedia
phpadmin:
image: phpmyadmin/phpmyadmin:latest
links:
- db
ports:
- '8080:80'
environment:
- PMA_ARBITRARY=1
apache:
image: 'php:7.2-apache'
restart: always
ports:
- '80:80'
volumes:
- ./html:/var/www/html
depends_on:
- db
links:
- db
Porém, ao tentar conectar com o banco no código PHP:
<?php
$servername = "localhost:3306";
$username = "root";
$password = "root";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
Este erro acontece:
Fatal error: Uncaught Error: Class 'mysqli' not found in /var/www/html/database/connection.php:7 Stack trace: #0 {main} thrown in /var/www/html/database/connection.php on line 7
Aparentemente a imagem do docker, php:7.2-apache
, não possui o mysqli.
Como faço para solucionar o problema e me conectar com o banco?