I am trying to connect from this docker container:
version: '3.8'
services:
vidslide-api:
image: php:8.1.17-apache
ports:
- "80:80"
volumes:
- ./htdocs:/var/www/html
command: >
sh -c "
docker-php-ext-install mysqli && \
docker-php-ext-enable mysqli && \
apache2-foreground
"
to this docker container:
version: '3.8'
services:
vidslide-db:
image: mysql:8.0.32
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: ***
ports:
- "3306:3306"
volumes:
- /var/lib/vidslide_mysql-db:/var/lib/mysql
volumes:
mysql_data:
I can connect to the mysql server with prisma and mysql workbench but not with php.
When I try to connect with mysqli:
$conn = mysqli_connect($host, $user, $pass, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
I get: Fatal error: Uncaught mysqli_sql_exception: No such file or directory in /var/www/html/index.php:14 Stack trace: #0 /var/www/html/index.php(14): mysqli_connect('localhost', 'root', '***', 'vidslide-db') #1 {main} thrown in /var/www/html/index.php on line 14
my mysqli config from phpinfo();
I don't understand the error message.
What do I have to do to make it work? Are the versions not compatible?