これはdatabase.phpです
class DatabaseConnection {
private $host;
private $port;
private $dbname;
private $username;
private $password;
public $query;
function __construct($host, $port, $dbname, $username, $password) {
$this->host = $host;
$this->port = $port;
$this->dbname = $dbname;
$this->username = $username;
$this->password = $password;
try {
$this->DBH = new PDO("pgsql:host=$this->host port=$this->port dbname=$this->dbname", "$this->username", "$this->password");
//echo "PDO connection object created";
}
catch(PDOException $e) {
echo $e->getMessage();
}
}
function query($query) {
$this->query = $query;
$this->STH = $this->DBH->prepare($this->query);
$this->STH->execute();
$this->STH->setFetchMode(PDO::FETCH_ASSOC);
}
}
$db = new DatabaseConnection('11.22.33.444','5432','eu','eu','eu123');
そして、これは私のauthorization.phpです
require 'database.php';
class Authorization extends DatabaseConnection {
public $vk_id;
public $eu_name;
public $eu_society;
public $eu_notes;
public $eu_want_team;
public function __construct() {
$this->vk_id = $_POST['vk_id'];
$this->eu_name = $_POST['eu_name'];
$this->eu_society = $_POST['eu_society'];
$this->eu_notes = $_POST['eu_notes'];
$this->eu_want_team = $_POST['eu_want_team'];
}
}
$auth = new Authorization();
$auth->query("INSERT INTO users (vk_id, eu_name, eu_society, eu_want_team, eu_notes) VALUES ($auth->vk_id, $auth->eu_name, $auth->eu_society, $auth->eu_want_team, $auth->eu_notes);");
database.php をインクルードし、認可クラスで query メソッドを使えるように拡張しました。しかし、今ではエラーが表示されます->
2 行目の /home/marker/entropia/components/database.php でクラス DatabaseConnection を再宣言できません