View Single Post
  #1 (permalink)  
Old 10-15-2008, 08:44 AM
Kakashi266's Avatar
Kakashi266 Kakashi266 is offline
Master Babbler
 
Join Date: Mar 2008
Posts: 201
Kakashi266 is a reputable WB member and has over 100 reputation pointsKakashi266 is a reputable WB member and has over 100 reputation points
Default PHP: store sessions in database

Hey guys and gals, I've got a little problem I've been working on for a few days now. I want to be able to store session information in my mysql database. I've read more tutorials on it than I can shake a stick at, but they haven't helped me at all. Even the ones that seem designed to do precisely what I want don't work. I've been doing some trial and error for the past day, but I haven't gotten anywhere useful.

So basically, while I continue my trial and error, I just wanted to put word out there, to see if someone can help me come up with the code.

**this is not a homework assignment or anything, just a little side-project of mine, so don't hold back, folks**

Anyway, I have a table called sessions, and the fields: session_Id, expiration, value.

Expiration is the current time plus the max life of the session, and value is the session data.

Currently, I have a command in the write() function (I'm creating a custom session handler) that should insert or update the table with new session information. The problem is that it does not work. I even echoed the data I wanted to insert right beneath it, and the data is there, just my mysqli commands are not working.

Here's code for consideration:
Code:
function write($id, $data)
{
	$newid = mysql_real_escape_string($id);
	$newdata = mysql_real_escape_string($data);

	$dbc = mysqli_connect('localhost','user','pass','database');
	$arg = "REPLACE sessions(session_Id,expiry,value) VALUES('$newid',time(),'$newdata')";
	$result = mysqli_query($dbc, $arg);
	return true;
}
Yeah, I know the time variable doesn't do what I wanted it to do, but I was just trying to get it to insert something.

I've gotta run right now, so if there's any other bit of code or information you need from me, let me know and I'll get it up asap. Thanks, guys.
__________________
I've designated Wednesday and Saturday as my official "Update the in-progress code on my sandbox site" days. So every Wednesday and Saturday, go here: http://www.foxneeson.exofire.net and check out the new features as I make them.
Reply With Quote