I finally got docker/xdebug/ & vs code to play together, now I’m having an issue when I load my page I get the following:
Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] No such file or directory in /var/www/html/index.php on line *5*
PDOException: SQLSTATE[HY000] [2002] No such file or directory in /var/www/html/index.php on line *5*
When I do a google search it seems most of the results are specific to laravel which I’m not using. I know one site suggested that I do something (I don’t remember what at this point but I’ve tried pretty much everything I’ve read) with the ip results after running:
docker inspect -f '{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)
which I did try a time or two. But using that seems tricky if I am using the result in my docker-compose.yml file as I would already need to know the correct ip to have it in the yml file to begin with, and it change from one
docker-compose up --build to the next (I am under the impression that anytime I change anything in docker-compose.yml or Dockerfile that the container needs to be rebuilt).
There error is happing when the debugger reaches the PDO instantiation line.
index.php
<?php
$dsn = "mysql:host=localhost;dbname=product_db;charset=utf8;port=3306";
$pdo = new PDO($dsn, 'product_db_user', 'secret', [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);
$stmt = $pdo->query('SELECT * FROM product');
$product = $stmt->fetchAll(PDO::FETCH_ASSOC);
print_r($prodcuts);
?>
docker-compose.yml
version: '3.1'
services:
php:
build:
context: .
dockerfile: Dockerfile
volumes:
[./:/var/www/html,
./docker/php/conf.d/php.ini:/usr/local/etc/php/php.ini,
./docker/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini,
./docker/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
]
ports:
["8081:80"]
stdin_open: true
tty: true
db:
image: mariadb:10.6
restart: always
volumes:
["./mariadb/data:/var/lib/mysql"]
ports:
["3306:3306"]
environment:
DATASOURCES_DEFAULT_HOST: db
MYSQL_ROOT_PASSWORD: notSecureChangeMe
MYSQL_USER: product_db_user
MYSQL_PASSWORD: secret
phpmyadmin:
image: phpmyadmin
restart: always
ports:
- 8082:80
environment:
- PMA_ARBITRARY=1
php.ini & xdebug.ini
zend_extension=xdebug.so
xdebug.mode=develop,coverage,debug,profile
xdebug.idekey=docker
xdebug.start_with_request=yes
xdebug.log=/dev/stdout
xdebug.log_level=0
xdebug.client_port=9003
xdebug.client_host=192.168.1.14
Thanks for any help, this container thing has been a major uphill battle.