Wrox Programmer Forums
|
BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1
This is the forum to discuss the Wrox book Professional PHP5 by Ed Lecky-Thompson, Heow Eide-Goodman, Steven D. Nowicki, Alec Cove; ISBN: 9780764572821
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 3rd, 2009, 06:13 AM
Registered User
 
Join Date: Feb 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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 :)
 
Old March 3rd, 2009, 06:33 AM
Registered User
 
Join Date: Feb 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
class UserSession {
private $php_session_id;
private $native_session_id;
private $objDB;
private $logged_in;
private $user_id;
private $session_timeout = 600; # 10 minute inactivity timeout
private $session_lifespan = 3600; # 1 hour session duration

public function __construct() {
# Connect to database 
try {
$this->objDB = Database::instance();
} catch (Exception $e) {
echo $e->getMessage();
exit(1);
}

...

public function Impress() {
if ($this->native_session_id) {
$result = $this->objDB->update('user_session', array('last_impression' => date("YmdHis")), "id = " . $this->native_session_id);
};
}

...

}
I'm find it.
I'm happy :)





Similar Threads
Thread Thread Starter Forum Replies Last Post
PEAR DB Connection failure bxh Beginning PHP 0 October 6th, 2005 10:25 PM
Anybody else learning to HATE pear::DB? biot023 BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 2 March 15th, 2005 04:58 AM
pear db::connect turing PHP Databases 1 September 15th, 2004 05:22 PM
PEAR::DB Using Problem ruhin Beginning PHP 5 June 4th, 2004 12:50 AM
Using PEAR DB and Classes. TreacherousDog Beginning PHP 1 July 8th, 2003 01:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.