0
I uploaded a PHP application with mysql through 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
However, when trying to connect to the database in PHP code:
<?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";
This error happens:
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
Apparently the image of Docker, php:7.2-apache
, does not own mysqli.
How do I solve the problem and me connect with the bank?