I'm trying to use a function from a class as follows:
$database = database::select("SELECT * FROM eventos");
When I run the code, it returns me the error:
Fatal error: Using this when not in context object in /var/www/html/folder/class/config.php on line 27
The class looks like this:
<?php
class database{
protected static $driver = 'mysql';
protected static $host = 'localhost';
protected static $port = 3306;
protected static $user = 'root';
protected static $pass = 'vertrigo';
protected static $database = 'noweb';
public $link = null;
public function __construct(){
try{
$this->link = new PDO(self::$driver.":host=".self::$host.";port=".self::$port.";dbname=".self::$database, self::$user, self::$pass);
}catch(PDOException $i){
die("Ocorreu um erro ao fazer conexão: <code>".$i->getMessage()."</code>");
}
}
static function select($sql){
$query = $this->link->query($sql);
$rs = $query->fetchAll(PDO::FETCH_OBJ) or die(print_r($query->errorInfo(), true));
return $rs;
}
}
?>
How can I fix this, and I want to call the functions of this class as follows:
database::FUNÇÃO('parametros');