5
MySQLのコンテナに接続する際に問題があります。ドッカーPHP、MySQL、nginx接続の問題で作成する
ドッキングウィンドウ-compose.yml
version: '2'
services:
mysql:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: JoeyW#1999
MYSQL_DATABASE: wiput
MYSQL_USER: web
MYSQL_PASSWORD: Web#1234
volumes:
- ./mysql:/var/lib/mysql
networks:
- code-network
php:
image: wiput1999/php:latest
volumes:
- ./code:/code
networks:
- code-network
nginx:
image: nginx:latest
ports:
- "80:80"
- "443:443"
volumes:
- ./code:/code
- ./site.conf:/etc/nginx/conf.d/default.conf
- /etc/letsencrypt:/etc/letsencrypt
networks:
- code-network
networks:
code-network:
driver: bridge
PHPテストスクリプト:
<?php
$servername = "localhost";
$username = "root";
$password = "JoeyW#1999";
try {
$conn = new PDO("mysql:host=$servername;dbname=wiput", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>
このスクリプトは、私をREPONSEは:
Connection failed: SQLSTATE[HY000] [2002] No such file or directory
私のコードで何が悪いのでしょうか?私はそれが大丈夫だと思うからだよ。
誰かがより良い解決策を持っていれば助けてくれてありがとう。
まだ同じ応答があります – wiput1999
それは今の仕事ありがとう:D – wiput1999