UserSession and Pear DB
Hi All! I'm reading this book and i have one question...
How to use class UserSession and pear DB?
class UserSession
{
public function __construct() {
// $this->dbhandle = pg_connect("host=db dbname=prophp5 user=ed") or die ("PostgreSQL error: --> " . pg_last_error($this->dbhandle));
$this->dbhandle = Database::instanse();
session_set_save_handler(
array(&$this, '_session_open_method'),
array(&$this, '_session_close_method'),
array(&$this, '_session_read_method'),
array(&$this, '_session_write_method'),
array(&$this, '_session_destroy_method'),
array(&$this, '_session_gc_method')
);
...
public function Impress() {
if ($this->native_session_id) {
// $result = pg_query("UPDATE \"user_session\" SET last_impression = now() WHERE id = " . $this->native_session_id);
// how to use pear DB in this query
};
}
...
}
class Database
{
private $conn;
private function __construct($dsn) {
//Open a connection using the info in $dsn
$this->conn = DB::connect($dsn);
if(DB::isError($this->conn)) {
//We're not connected. Throw an exception
throw new Exception($this->conn->getMessage(), $this->conn->getCode());
}
//Always fetch data as an associative array
$this->conn->setFetchMode(DB_FETCHMODE_ASSOC);
}
static public function instanse()
{
static $objDB;
if(!isset($objDB))
{
$objDB = new Database(DSN);
}
return $objDB;
}
...
}
red = It's so good?
green = please give me example
Please Help Me :)
|