Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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 :)
  #2 (permalink)  
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 :)
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:33 PM.


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