dakata__92
Super Moderator
Написах си един клас за връзка с база данни но желая да добавя такъв метод.
PHP:
<?php
namespace CCF\DB;
class MySQLi{
private static $instance = Null;
private $results;
private $db;
private $DB_HOST = 'localhost';
private $DB_USER = 'root';
private $DB_PASS = '';
private $DB_NAME = 'oop';
private function __construct(){
$this->db = new \mysqli($this->DB_HOST, $this->DB_USER, $this->DB_PASS, $this->DB_NAME);
if($this->db->connect_errno > 0){
throw new \Exception("No connection with database.",500);
}
}
public static function getInstance(){
if (self::$instance == Null){
self::$instance = new self;
}
return self::$instance;
}
public function query($sql){
$query = $this->db->query($sql);
if($query){
return $query;
}
else{
throw new \Exception("SQL error.",500);
}
}
public function close(){
if($this->db){
$this->db->close();
}
}
}
?>