Hello,
Been searching for an answer on why I’m getting this error (Fatal error: Call to a member function prepare() on a non-object ) but can’t come up with anything. Just trying to learn and update a single table in a test database. I’ll post the code for both classes I’m using so maybe I can get some help with figuring out the issue. Thank you to in advance for any advice
class.database.php
[php]
class dbConnect{
protected $db_conn;
public $db_name =‘test’;
public $db_user = ‘root’;
public $db_pass= ‘’;
public $db_host=‘localhost’;
function connect(){
try{
$this->$db_conn = new PDO("mysql:host=$this->db_host;dbname=$this->$db_name",$this->db_user,$this->$db_pass);
return $this->db_conn;
}
catch(PDOException $e){
return $e->getMessage();
}
}
}
[/php]
class.manageUsers.php
[php]
include_once(‘class.database.php’);
class ManageUsers{
public $link;
function _construct(){
$db_connection = new dbConnect();
$this->link = $db_connection->connect();
return $this->link;
}
function RegisterUsers($username,$password,$ip_address,$time,$date){
$query = $this->link->prepare("INSERT INTO users (username,password,ip_address,date,time) VALUES(?,?,?,?,?)");
$values = array($username,$password,$ip_address,$time,$date);
$query->execute($values);
$counts = $query->rowCount();
return $counts;
}
}
$users = new ManageUsers();
echo $users->RegisterUsers('bob','bob','127.0.0.1','12:00',31-01-2012);
[/php]