DEV Community

Discussion on: PHP + MySQL using Docker Compose

Collapse
 
vladimir_efremenko_af2271 profile image
Vladimir Efremenko

When working with the database from the application, I get the following:
Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /var/www/html/index.php:6 Stack trace: #0 {main} thrown in /var/www/html/index.php on line 6

Connection code:
<?php
$servername = "localhost:9906";
$username = "devuser";
$password = "devpass";
$dbname = "test_db";
$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Fatal error: " . mysqli_connect_error());
if (mysqli_connect_errno()) {
printf("Fatal error: %s\n", mysqli_connect_error());
exit();
}
?>

With the help of mysqlworkbench i can connect and work with the database!
Tell me where I went wrong and why it doesn't work?