Non-object error
still didnt found an solution for these. Look.
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('154.326.11.45','5432','eu','eu','eu123');
authorization.php
require_once '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'];
}
function query($query) {
$this->query = $query;
$this->STH = $this->DBH->prepare($this->query);
$this->STH->bindParam(':vk_id', $this->vk_id);
$this->STH->bindParam(':eu_name', $this->eu_name);
$this->STH->bindParam(':eu_society', $this->eu_society);
$this->STH->bindParam(':eu_notes', $this->eu_notes);
$this->STH->bindParam(':eu_want_team', $this->eu_want_team);
$this->STH->execute();
$this->STH->setFetchMode(PDO::FETCH_ASSOC);
}
}
$auth = new Authorization();
$auth->query("INSERT INTO users (vk_id, eu_name, eu_society, eu_notes,
eu_want_team)VALUES (:vk_id, :eu_name, :eu_society, :eu_notes,
:eu_want_team);");
It tells
Call to a member function prepare() on a non-object in
/home/marker/entropia/components/authorization.php on line 21
Line 21 is - $this->STH = $this->DBH->prepare($this->query);
The problem is in DBH, but authorization inherit from database, and in
database class's constructor is running:
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();
}
So whats the problem? Waiting for solution and explain. Thanks!
No comments:
Post a Comment