Hello,
As a short introduction, I primarily do graphic/web design for a small company and being the only computer savvy employee I've been tasked with remedying the situation. I have very limited PHP knowledge and would greatly appreciate any help.
The servers were updated to PHP 5.3 from 5.2 just prior to the new year and not surprisingly our meeting database went down due to incompatible/deprecated code.
The code, from what I understand, was done 3-4 years ago from a contract. I have google'd quite extensively to try and get a handle on PHP but it hasn't led to any meaningful results. I'm not looking for a thorough solution as it would probably result in rewriting quite a bit of code since I understand that there are more deprecated functions going from 5.3->5.5; I just want to understand why this particular instance is happening and work from there.
These are the errors that are showing up:
Deprecated: Function mysql_db_query() is deprecated in /sites/www.redacted.org/htdocs/register/include/sessions.php on line 46
Deprecated: mysql_db_query() [function.mysql-db-query]: This function is deprecated; use mysql_query() instead in sites/www.redacted.org/htdocs/register/include/sessions.php on line 46
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /sites/www.redacted.org/htdocs/register/include/sessions.php:46) in /sites/www.redacted.org/htdocs/register/include/funcs_db.php on line 11
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /sites/www.redacted/htdocs/register/include/sessions.php:46) in /sites/www.redacted.org/htdocs/register/include/funcs_db.php on line 11
Warning: Cannot modify header information - headers already sent by (output started at /sites/www.redacted.org/htdocs/register/include/sessions.php:46) in /egr/sites/www.redacted.org/htdocs/register/input.php on line 179
The following is the sessions.php code:
<?php
class SessionManager
{
var $life_time;
function SessionManager() {
// Read the maxlifetime setting from PHP
$this->life_time = 3600;
// Register this object as the session handler
session_set_save_handler(
array( &$this, "open" ),
array( &$this, "close" ),
array( &$this, "read" ),
array( &$this, "write"),
array( &$this, "destroy"),
array( &$this, "gc" )
);
}
function open( $save_path, $session_name ) {
global $sess_save_path;
$sess_save_path = $save_path; // Don't need to do anything. Just return TRUE.
return true;
}
function close() {
return true;
} function read( $id ) {
// Set empty result
$data = '';
// Fetch session data from the selected database
$time = time();
$newid = mysql_real_escape_string($id);
$sql = "SELECT `session_data` FROM `reg_session` WHERE `session_id` = '$newid' AND `expires` > $time";
$rs = mysql_db_query(preservation,$sql);
$a = mysql_num_rows($rs);
if($a > 0) {
$row = mysql_fetch_assoc($rs);
$data = $row['session_data'];
}
return $data;
}
function write( $id, $data )
{
// Build query
$time = time() + $this->life_time; $newid = mysql_real_escape_string($id);
$newdata = mysql_real_escape_string($data);
$sql = "REPLACE `reg_session` (`session_id`,`session_data`,`expires`) VALUES('$newid', '$newdata', $time)";
$rs = mysql_db_query(preservation,$sql);
return TRUE;
}
function destroy( $id ) {
// Build query
$newid = mysql_real_escape_string($id);
$sql = "DELETE FROM `reg_session` WHERE `session_id` = '$newid'";
mysql_db_query(preservation,$sql);
return TRUE;
}
function gc() {
// Garbage Collection
// Build DELETE query. Delete all records who have passed
// the expiration time
$sql = 'DELETE FROM `reg_session` WHERE `expires` < UNIX_TIMESTAMP();';
mysql_db_query(preservation,$sql);
// Always return TRUE
return true;
}
}
?>
The following is the funcs_db.php code:
<?php
/*******
This include file is meant for any functions that involve database queries
********/
/*****Initializes session_set_save_handler*****/
function createSession()
{
require_once("./include/sessions.php");
$sess = new SessionManager();
session_start();
}
//*******Determines additional fields in database***********//
function findExtraFields($meeting_id,$db_link)
{
$eventquery = 'SELECT * FROM preservation.meeting_info WHERE meeting_id=\''.$meeting_id.'\'';
$eventresults = mysql_query($eventquery, $db_link) or die (mysql_error());
$erow = mysql_fetch_assoc($eventresults);
$field_list = mysql_query('DESCRIBE preservation.'.$erow['meeting_database'],$db_link);
$common_fields = array('person_id', 'Date', 'First_Name', 'Last_Name', 'Title', 'Agency', 'Email', 'Phone', 'Address', 'City', 'State', 'Country', 'Zip', 'notes');
$extra_fields = array();
while ($i = mysql_fetch_assoc($field_list))
{
if(!in_array($i['Field'],$common_fields))
{
array_push($extra_fields,$i['Field']);
}
}
return $extra_fields;
}
?>
So far I've tried replacing all the deprecated "mysql_db_query()" functions to "mysql_query" but that leads to a new error which I assume has to do with the "$sql" variable.
Warning: mysql_query() expects parameter 2 to be resource, string given in /sites/www.redacted.org/htdocs/register/include/sessions.php on line 46
Warning: mysql_num_rows() expects parameter 1 to be resource, null given in /sites/www.redacted.org/htdocs/register/include/sessions.php on line 47
I also tried a mysql connection check to the database and that seemed to work.
$db = mysql_connect("redacted", "redacted", "redacted");
mysql_select_db("preservation",$db);
if (!$db)
{
echo "Failed to connect to MySQL: " . mysql_error();
} else { echo "Connection was OK!\n";}
Thanks for reading.