Answer the question
In order to leave comments, you need to log in
What is wrong with []?
Good afternoon!
There is a code
<?php
class DB {
private static $instance;
private static $db;
public static function obj()
{
$class=get_called_class();
if (is_null(self::$instance))
{
self::$instance=new $class;
self::$db=new PDO("mysql:dbname=news_db;host=localhost","root","");
}
return self::$instance;
}
public function connect(){
return self::$db;
}
public function queryAll($sql){
$quer=$this->connect()->query($sql);
if (is_null($quer)) {
return [];
}
return $quer->fetchALL(PDO::FETCH_ASSOC);
}
public function queryOnce($sql){
$quer=$this->connect()->query($sql);
if (is_null($quer)) {
return [];
}
return $quer->fetch(PDO::FETCH_ASSOC);
}
}
$new_connect=DB::obj()->connect();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question