Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Database object in session_set_save_handler()
Old 07-01-2008, 08:47 AM Database object in session_set_save_handler()
Novice Talker

Posts: 6
Name: Marc
Location: England
Trades: 0
Okay so setup my script, however when i execute i get this error

Fatal error: Call to a member function fetch_one() on a non-object

I know that the object exists as it is used everywhere around the site

function psess_write($id, $sess_data) {
global $db;
$data = hb_filterClientData($sess_data);
if ($db->fetch_one("SELECT COUNT(*) FROM sessions WHERE sess_id='$id'") == 0) {
$result = $db->query("INSERT INTO sessions (sess_id, sess_data, sess_updated) VALUES ('$id', '$data', UNIX_TIMESTAMP(NOW()))");
if ($db->affected_rows() == 0) return false;
} else {
$db->query("UPDATE sessions SET sess_data='$data',sess_updated=UNIX_TIMESTAMP(NOW( )) WHERE sess_id='$id'");
}
return true;
}

That is the code i am using, and i know the $db object exists, and i have set it to global but still no luck, have i missed something simple?

Thanks
Marc
Marc.Qualie is offline
Reply With Quote
View Public Profile Visit Marc.Qualie's homepage!
 
 
Register now for full access!
Old 07-01-2008, 09:30 AM Re: Database object in session_set_save_handler()
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
I know that the object exists as it is used everywhere around the site
What about testing it ?
From what PHP tells you, it's not existant, or not an object.
Maybe it's initialized after that you reach that part of the code.

Try to put an
PHP Code:
echo "<pre>".var_dump($db)."</pre>"
just after global $db.
It will dump the value of $db, and I think it will say "null" or "false"...
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 07-01-2008, 03:49 PM Re: Database object in session_set_save_handler()
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
You probably have to call session_write_close yourself. Read this note from session_set_save_handler:
Quote:
Warning As of PHP 5.0.5 the write and close handlers are called after object destruction and therefore cannot use objects or throw exceptions. The object destructors can however use sessions.
It is possible to call session_write_close() from the destructor to solve this chicken and egg problem.
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Database object in session_set_save_handler()
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12109 seconds with 12 queries