i have these in Database.php
class Database
{
private $dbname = 'auth';
private $db_instance;
public function __construct($q)
{
if(!$this->db_instance)
$this->db_instance = new SQLite3($q);
}
private function init()
{
if(!$this->db_instance)
{
$this->db_instance = new SQLite3($dbname);
}
}
private function close()
{
if($this->db_instance)
$this->db_instance->close();
}
static public function fetch_a_row($q)
{
$this->init();
$res = $this->db_instance->query(SQLite3::escapeString($q));
$ret = $res->fetchArray(SQLITE3_ASSOC);
$this->close();
return $ret;
}
static public function exec($q)
{
$this->init();
$this->db_instance->exec(SQLite3::escapeString($q));
$this->close();
}
}
in try to call him on index.php
<?php
require_once('Database.php');
$ret = Database::fetch_a_row('SELECT * FROM user WHERE uname = "test"');
echo $ret['id'];
?>
but response :
Fatal error: Using $this when not in object context in /www/cgi-bin/auth/Database.php on line 29
is there anyone could help ? thank in advance