samedi 7 février 2015

PHP - Using $this when not in object context


When I try to execute this code from inherited class I got this error Using $this when not in object context here my code



abstract class Connection {

private static $host;
private static $username;
private static $password;
private static $database;

public function __construct() {
self::$host = 'localhost'; // database server address
self::$username = 'root'; //database server username;
self::$password = ''; //database server password;
self::$database = 'oms'; //database name
}

private function connect() {
return new PDO('mysql:host=' . Connection::$host . ';dbname=' . Connection::$database . '', Connection::$username, Connection::$password);
}

protected function execute($sql) {
$this->connect();
return $this->connect()->query($sql);
}

}


what are the reason for that? i don't use any static method in Connection class. SoWhy do give this error?





Aucun commentaire:

Enregistrer un commentaire