A ver, si yo tengo esta clase asi (clase que hice yo y no se que tan ventajosa es o si no estoy haciendo algo estupido, por favor me lo dicen), estoy aplicando el singleton?
y para usarla me alcanzaría con esto?
$DB::getInstance();
$DB->consulta("select.....");
es así?
Código PHP:
<?
class DB extends mysqli
{
private $query;
private $errores;
private static $_instance = null;
function __construct()
{
parent::__construct("localhost", "user", "pass", "base");
$this->errores();
}
public static function getInstance()
{
if( self::$_instance == null ) {
self::$_instance = new self();
}
return self::$_instance;
}
function __destruct() {
parent::close();
}
function consulta($consulta)
{
$this->query = parent::query($consulta);
$this->errores();
}
function Fetch()
{
if($this->query != NULL)
{
return $this->query->fetch_array(MYSQLI_ASSOC);
}
$this->errores();
}
function actualizar($consulta)
{
$query = parent::query($consulta);
$this->errores();
return;
}
function numRegistros()
{
return $this->query->num_rows;
}
private function errores()
{
if ($this->errno)
{
echo $this->errores = "ERROR: \n".$this->error;
return ;
}
}
}
?>