php - PDO returning nothing on a different web server

681

this problem has been driving me crazy for the past few days. I made a DB Wrapper to connect and interact with my mysql database and all works fine on my localhost running PHP5.4.12 however when I moved it over to my VPS (currently hosting an xenforo forum) in a/forums directory, as soon as the first query hits, it kills the rest of the page. On my localhost, the queries run and the content is shown. On the VPS, once the page hits the query it stops loading the rest of the page and leaves it blank.

Here's my DB.php:

class DB{
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 DB();
    }
    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;
}

public function action($action, $table, $where = array()){
    if(count($where) === 3){
        $operators = array('=', '>', '<', '>=', '<=');

        $field      = $where[0];
        $operator   = $where[1];
        $value      = $where[2];

        if(in_array($operator, $operators)){
            $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?";

            if(!$this->query($sql, array($value))->error()){
                return $this;
            }
        }
    }
    return false;
}

public function get($table, $where){
    return $this->action('SELECT *' , $table, $where);
}

public function place($number){
    return $this->results()[$number];
}

public function results(){
    return $this->_results;
}

public function error(){
    return $this->_error;
}

public function count(){
    return $this->_count;
}

}

The thing that is really driving me crazy is there are no errors! I've seterror_reporting(E_ALL) and still nothing. The PHP version on the VPS is5.3.3. If you need anymore information please just ask and I'll edit it in.

People are also looking for solutions to the problem: arrays - comparison operation in if statment php

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.