View Single Post
Old 14th July 2007, 22:37
Mosquito Mosquito is offline
Join Date: Nov 2006
Posts: 85
Thanks: 5
Thanked 6 Times in 5 Posts

Originally Posted by falko
How did you initialize $connection?

Is the include_path the same in php.ini on your windows and Linux system?
The only include that is different between the two environments is the addition of the Smarty Templating directory on Linux.

include_path = ".;c:\php\includes;c:\php\extras\libs;./include;C:\PHP\PEAR\pear"

include_path = ".:/usr/share/php:/usr/local/lib/php/Smarty/:/usr/share/pear/:./include"

To initialize, the connection is declared as global. In the begin_session function, the connection is set up. This connection works fine if I am just trying to read the session data, but if I try to write to the session table, the query function is unknown.

This is the Begin_Session function:
// Globals

Begin_Session($db_name, $tb_name)
	global $connection;
	global $session_table;
	$connection = new db_conn($db_name);
	$session_table = $tb_name;
	return true;
This is the Read_Session function
function Read_Session($sess_id)
	global $connection;
	global $session_table;
	$query_result = $connection->query("SELECT * FROM $session_table WHERE session_id = '$sess_id'");
	if(mysql_num_rows($query_result) == 0) 	
		return ""; // No session exists	
	else  // Session exists. Yay!			
		return mysql_result($result,0,1);
This is the Write_Session function
function Write_Session($sess_id, $add_to_session) 
	global $connection;
	global $session_table;
	$seconds = getMicroTime();    // This function just returns seconds since 1970
	$query_result = $connection->query("SELECT session_id FROM $session_table WHERE session_id = '$sess_id'");
	$add_to_session = addslashes($add_to_session);
	if(mysql_num_rows($query_result) == 0) // If no session exists, make this a new session
		$connection->query("INSERT INTO $session_table (session_id, session_variable, last_accessed) VALUES('$sess_id','$add_to_session',$seconds)");
	else // Session already exists, so update session data
		$connection->query("UPDATE $session_table SET session_variable = '$add_to_session', last_accessed = $seconds WHERE session_id = '$sess_id'");
	return true;
Reply With Quote