セッションデータをデータベースに保存するクラスを作成しました。データベースに保存されておらず、エラーはありません。理由はありますか?ここにクラスがあります。
<?php
class Session {
public function __construct(){
//set handle to override SESSION
$session_id = session_id();
$session_name = session_name();
$session_path = session_save_path();
echo "in class";
}
function open(){
include("includes/globals.php");
global $_sess_db;
echo "in open";
if(mysql_connect('127.0.0.1','root','') or die(mysql_error())){
return mysql_select_db($CallPro_dbname, $_sess_db);
echo "connected";
}
return FALSE;
}
function close(){
global $_sess_db;
return mysql_close($_sess_db);
}
function read($session_id){
mysql_connect('127.0.0.1','root','');
$record;
$sql = "select * from callprodev.session_data where agentid = '".$_SESSION['agentid']."'";
$result = mysql_query($sql,$_sess_db)or die(mysql_error());
$record = mysql_fetch_assoc($result)or die(mysql_error());
echo "read";
}
function write($session_id){
mysql_connect('127.0.0.1','root','');
$access = time();
$access = mysql_real_escape_string($access);
$sql = "REPLACE
INTO callprodev.session_data
VALUES (
'{$_SESSION['agentid']}',
'{$_SESSION['extension']}',
'{$_SESSION['page']}',
'{$_SESSION['vduser']}',
'{$_SESSION['vdpass']}',
'{$_SESSION['action_main_plugin']}',
'{$_SESSION['caller_phone']}',
'{$_SESSION['campaignid']}',
'{$_SESSION['uniqueid']}',
'{$_SESSION['dialed']}',
'{$_SESSION['rurl']}',
'{$_SESSION['reference_id']}',
'{$_SESSION['contactid']}',
'{$_SESSION['groupid']}',
'{$_SESSION['script_info_plugin']}',
'{$_SESSION['flags']}',
'{$_SESSION['dispositioned']}'
)";
echo "write";
return mysql_query($sql, $_sess_db)or die(mysql_error());
}
function destroy($session_id){
mysql_connect('127.0.0.1','root','');
$sql = "delete from callprodev.session_data where id = '{$_SESSION['agentid']}'";
echo "destroy";
return mysql_query($sql, $_sess_db)or die(mysql_error());
}
function gc($max){
}
}
$session_record = new Session();
session_set_save_handler(
array($session_record, "open"),
array($session_record, "close"),
array($session_record, "read"),
array($session_record, "write"),
array($session_record, "destroy"),
array($session_record, "gc"));
register_shutdown_function('session_write_close');
session_start();
セッションは init.php ファイルに含まれています。このように呼ばれています。
include("classes/Session.php");
$session_record = new Session();
session_set_save_handler(
array($session_record, "open"),
array($session_record, "close"),
array($session_record, "read"),
array($session_record, "write"),
array($session_record, "destroy"),
array($session_record, "gc"));
session_start();