Home » Php » php – Zend Framework with Docker, data is null

php – Zend Framework with Docker, data is null

Posted by: admin February 25, 2020 Leave a comment

Questions:

I tried to dockerize my website with PHP, MariaDB and Apache.

Actually the docker is working, no error inside and good communication between each service.

But I get an error with PDO (SQL Syntax).

$auth = new Auth();
$this->_auth = $auth->getIdentity();
  • When I print $auth with print_r, I get a big array that I can’t print totally, there is something inside.

  • When I print $this->_auth, I only get one string that is incompatible with my rest of program.

Portions that can help to understand :

Notice: Trying to get property of non-object in /var/www/html/module/MyProject/src/MyProject/Model/MenuTable.php on line 33

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AND d.TableRef = 'page') OR page.Publique = 1) AND Deconnecte = 1 ORDER BY `Ordr' at line 9' in /var/www/html/vendor/zendframework/zendframework/library/Zend/Db/Adapter/Driver/Pdo/Statement.php:240 Stack trace: #0 /var/www/html/vendor/zendframework/zendframework/library/Zend/Db/Adapter/Driver/Pdo/Statement.php(240): PDOStatement->execute() #1 /var/www/html/vendor/zendframework/zendframework/library/Zend/Db/TableGateway/AbstractTableGateway.php(233): Zend\Db\Adapter\Driver\Pdo\Statement->execute() #2 /var/www/html/vendor/zendframework/zendframework/library/Zend/Db/TableGateway/AbstractTableGateway.php(208): Zend\Db\TableGateway\AbstractTableGateway->executeSelect(Object(Zend\Db\Sql\Select)) #3 /var/www/html/vendor/zendframework/zendframework/library/Zend/Db/TableGateway/Abs in /var/www/html/vendor/zendframework/zendframework/library/Zend/Db/Adapter/Driver/Pdo/Statement.php on line 245

MenuTable line 33

$idInscrit = (isset($idInscrit) ? $idInscrit : (isset($this->_auth) ? $this->_auth->IDInscrit : 0));

Portion of code where the PDO error happens.

                    ->where("(page.IDPage IN (
                                SELECT d.IDLigne
                                FROM inscrit i
                                JOIN lien_inscrit_role lir ON lir.IDInscrit = i.IDInscrit
                                JOIN lien_droit_role ldr ON ldr.IDRole = lir.IDRole
                                JOIN droit d ON d.IDDroit = ldr.IDDroit
                                JOIN page p ON p.IDPage = d.IDLigne
                                WHERE i.IDInscrit = $idInscrit
                                AND d.TableRef = 'page')"
                            . " OR page.Publique = 1)");

docker-compose.yml

version: '3.2'
services:
    mariadb:
        build: ./mariadb
        container_name: mariadb
        restart: always
        ports:
          - '3306:3306'
        environment:
          - MYSQL_DATABASE=${MYSQL_DATABASE}
          - MYSQL_USER=${MYSQL_USER}
          - MYSQL_PASSWORD=${MYSQL_PASSWORD}
          - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
          - TZ=Europe/London

    php:
        build: ./php-fpm
        container_name: php
        ports:
            - '9002:9000'
        links:
            - mariadb
        volumes:
          - .:/var/www/html/

    apache:
        build: .
        container_name: apache
        links:
          - mariadb
          - php
        volumes:
          - .:/var/www/html/
        ports:
          - '8085:80'

    phpmyadmin:
        image: phpmyadmin/phpmyadmin
        links:
            - mariadb
        ports:
            - '8183:80'
        environment:
            - MYSQL_USER=${MYSQL_USER}
            - MYSQL_PASSWORD=${MYSQL_PASSWORD}
            - PMA_HOST=mariadb

I tried in local, when I print $this->_auth I get an array, that’s what i’m looking for for my docker, and it works.

I think the problem come from the framework or connection between database and server.

How can I fix this ?

How to&Answers: