Hi All, I am trying to connect to a database OOP singleton method.
I am getting an error "syntax error, unexpected 'function_construct'" and I unable to find the syntax error in the code.
Any help with this would be appreciated.
Thanks in advance
David
// Page: index.php
<?php
require_once 'classes/db.php';
echo '<pre>', print_r(DB::getInstance()->query('SELECT * FROM Users')->results()), '</pre>';
//classes/db.php
<?php
//classes/db.php
class DB
{
private $_mysqli,
$_query,
$_results = array(),
$_count=0;
public static $instance;
public static function getInstance(){
if (isset(self::$instance)){
self::$instance = new DB();
}
return self::$instance;
}
public function_construct(){
$this->_mysqli = new mysqli('localhost','xxxx','xxxxx','db301847341');
if($this->_mysqli->connect_error) {
die($this->_mysqli->connect_error);
}
}
public function query($sql){
if($this->_query= $this->_mysqli->query($sql)){
while ($row = $this->_query->fetch_object()){
$this->_results[] = $row;
}
}
return $this;
}
public function result(){
return $this->_results;
}
}