0

FIXED: The problem was the spl_autoloader dosent work on the webserver for some reason and there was one typeo in my code that worked on my machine but not the webserver.

Trying to solve a problem on my website where it works on my machine but not the Google hosted VM.

The database can receive data but i cant seem to get it to display data through JSON POST requests or login through the login system.

I have a feeling the database is not "sending" data to PDO.

Is there a log or something i can do to check requests to the database?

System info: http://www.interplanetaryhub.com/phpinfo.php

Database connecting code thats works on my machine but not the webhost VM

<?php
    class Database {
        private static $_instance = null;
        private $_pdo,
                $_query,
                $_error = false,
                $_results,
                $_count = 0;

        private function __construct() {
            try {
                $this->_pdo = new PDO('mysql:host='.Config::get('mysql/host').';dbname='.Config::get('mysql/db'),Config::get('mysql/username'),Config::get('mysql/password'));
            } catch (PDOException $e) {
                die($e->getMessage());
            }
        }

        public static function getInstance() {
            if (!isset(self::$_instance)) {
                self::$_instance = new Database();
            }
            return self::$_instance;
        }

        public function query($sql, $params = array()) {
            $this->_error = false;
            if ($this->_query = $this->_pdo->prepare($sql)) {
                $x = 1;
                if (count($params)) {
                    foreach ($params as $param) {
                        $this->_query->bindValue($x, $param);
                        $x++;
                    }
                }

                if ($this->_query->execute()) {
                    $this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ);
                    $this->_count   = $this->_query->rowCount();
                } else {
                    $this->_error = true;
                }
            }

            return $this;
        }
  • Either the user doesn't have access to perform the query, or you are incorrectly using the data or incorrectly sending the query. Without seeing your actual code that doesn't work, with an explanation of how it *should* work, we can't really me much of help. – Qirel Sep 22 '20 at 08:29
  • Ill add some code that might be the culprit but im doubting it – Alexander Fraser Sep 22 '20 at 09:23
  • We have no idea how you're using that. You should ensure the user has permission to that database too. and set up PDO to throw exceptions on failure, see https://stackoverflow.com/questions/8992795/set-pdo-to-throw-exceptions-by-default – Qirel Sep 22 '20 at 09:29
  • ive checked permissions for the database and the user does have permissions. I will attempt to further investigate throwing exceptions but i dont quite understand atm. – Alexander Fraser Sep 22 '20 at 09:45
  • You should never check any permissions out of the blue. Obtain the **error message** first and only then go straight to fix the actual error. – Your Common Sense Sep 22 '20 at 11:29
  • You don't have to understand exceptions. They are the same as regular errors. All you need is the error message, no matter whether it's from exceptions or anything else – Your Common Sense Sep 22 '20 at 11:30
  • Not getting an error msg will try to find it. There is nothing in any logs i have looked at and there is nothing provided to the user except the the JSON is empty. – Alexander Fraser Sep 23 '20 at 12:12

0 Answers0