Jump to content
Larry Ullman's Book Forums

Sessions Stored In Db Functions


Recommended Posts

I switched over to storing them into a db as done in the book but I notice that when my code has errors, often it leads to an error in the write_session() function. Calling on a function on a non-object, $dbc. The funny thing is that there is no code to write to the session but there is code to read session data.

 

It appears to be trying to write a session before opening the session and establishing a db connection. I confirmed it by putting code inside the write_session() function to open a new connection at each call.

Link to comment
Share on other sites

I altered your code to use PDO without any problems....except when one of my queries goes bad. Then I get two errors....

 

Fatal error: Call to undefined method PDOStatement::prepare() in \finalize.php on line 139

Fatal error: Call to a member function prepare() on a non-object in \db_sessions.inc.php on line 84

 

The first was from a failed query. The second is line #84 which is the write_session() function. The funny thing is that if I insert code to establish $dbc inside write_session() and rerun that would eliminate the second error.

 

Then I put simple echo statements in the open_session() and write_session() and whenever my query goes bad it fails to open_session() before write_session() which is why I get the second error. Do you know why this is happening?

 

 

Sorry for late response, I did not subscribe to topic.

Link to comment
Share on other sites

  • 2 weeks later...

I'm making the assumption that your database resource link is stored in $dbc. If you use a different variable name, you'll need to change that conditional. Be sure to check the PHP Manual page on the proper use of error_code(). The example block of code should only attempt to process your PDO statements if there were no errors in your last database operation.

 

I can't provide too much help here, since I've never used PDO myself. In fact, we have such an old version of PHP on our server, I've stuck to procedural coding, so I'm not very well versed in OOP.

Link to comment
Share on other sites

 Share

×
×
  • Create New...