0

I have the main page (index.php) and a database page (DB.php). Index.php makes a call at the DB page. The code appears to show no errors, but the results do not appear, which in this case is an echo statement.

<?php 
require_once 'core/init.php';

DB::getInstance();

This is index.php

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

    public 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'));
         echo "sad";
    	}catch(PDOException $e){
    		die($e->getMessage());
    	}
        }
public static function getInstance(){
      if(!isset(self::$_instance)){
        self::$_instance = new DB();
        }
return self::$_instance;
}

}

This is DB.php

4
  • what is your expected results ? Commented Mar 15, 2019 at 7:56
  • a print of 'sad'. its set up as an echo in the _construct function Commented Mar 15, 2019 at 7:58
  • assign DB::getInstance(); to a variable and var_dump() it Commented Mar 15, 2019 at 8:00
  • just did that. am only getting the first half of up untill $count = 0 Commented Mar 15, 2019 at 8:03

1 Answer 1

1

I think you have an error here:

public function _construct() {

should be two underscores:

public function __construct() {

It just seems the constructor is not called which would explain the entire behavior.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.