0

I have a docker-compose file as follows:

version: '3.8'
services:
    php-apache-environment:
        container_name: php-apache
        build:
            context: ./php
            dockerfile: Dockerfile
        depends_on:
            - db
        volumes:
            - ./php/src:/var/www/html/
        ports:
            - 8000:80
    phpmyadmin:
        image: phpmyadmin/phpmyadmin
        ports:
            - '8080:80'
        restart: always
        environment:
            PMA_HOST: db
        depends_on:
            - db
    db:
        container_name: db
        image: mysql
        command: --default-authentication-plugin=mysql_native_password
        restart: always
        environment:
            MYSQL_ROOT_PASSWORD: MYSQL_ROOT_PASSWORD
            MYSQL_DATABASE: MYSQL_DATABASE
            MYSQL_USER: MYSQL_USER
            MYSQL_PASSWORD: MYSQL_PASSWORD
        ports:
            - "9906:3306"
  

The dockerfile has the MYSQLI extension as follows:

FROM php:7.3-apache
COPY src/ /var/www/html/
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
RUN apt-get update -y && apt-get install -y curl && apt-get clean -y
RUN apt-get update && apt-get upgrade -y

I am trying to query the database after connection for the presence of various data however there is no return - breakpoint is on $conn->get in the following snippet of an API container.

<?php

// return api results
header('Content-Type: application/json; charset=utf-8');
header("Access-Control-Allow-Origin: *");


include_once('functions.php');
include_once('config.php');


$conn = new mysqli($host, $user, $pass, $mydatabase, $port);
if ($conn->connect_error) {
    _log("Connection error : " . $conn->connect_error);
} else {
    _log("Connected to MySQL server successfully!");
}


$email = $_GET['email'];



$select_query = "SELECT user_password, user_id, user_email, user_status FROM user_login WHERE user_email = '{$email}';";
_log("SQL Query : " . $select_query);

$result = mysqli_query($conn, $select_query);
_log("Result 1 : " . $result);

I have also tried using:

$result = $conn->query($select_query);

My config file is correct to my knowledge as it allows connection and is as follows:

<?php

$host="db";
$user="MYSQL_USER";
$pass="MYSQL_PASSWORD";
$mydatabase = 'MYSQL_DATABASE';
$port = '3306'

?>

Container logs are as follows:

[Tue Sep 06 01:43:41.299093 2022] [php7:notice] [pid 17] [client 172.22.0.9:41046] Connected to MySQL server successfully!
[Tue Sep 06 01:43:41.299157 2022] [php7:notice] [pid 17] [client 172.22.0.9:41046] SQL Query : SELECT user_password, user_id, user_email, user_status FROM user_login WHERE user_email = 'abcde@gmail.com';

Is there another way to query data in a docker container for a phpmyadmin database? Or anyone know of a workaround for the above code?

  • What _do_ you see from your logging / debugging? Where and how does your code fail? Have you [enabled error reporting](https://stackoverflow.com/a/845025/283366)? What values are you using for `$host` and `$port`? – Phil Sep 06 '22 at 02:08
  • @Phil I've updated my post. _log($result) returns nothing and isn't visible, the code that continues after the above receives no input and all further _logs for the file aren't visible in the logs. – Aidan Campbell Sep 06 '22 at 02:16

0 Answers0