<?php
try{
$conn = new PDO("mysql:host=$DB_SERVER;dbname=$DB_NAME",$DB_USER,$DB_PASS);
}
class SessionManager {
var $life_time;
function SessionManager() {
global $conn;
$this->life_time = get_cfg_var("session.gc_maxlifetime");
// 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 read( $id ) {
global $conn;
$data = "";
$time = time();
$newid = $id;
$sql = "SELECT session_data FROM session_tmp WHERE session_id=? AND expired_date > ?";
$q = $conn->prepare($sql);
$result = $q->execute(array($newid, $time));
while($r = $q->fetch(PDO::FETCH_ASSOC)){
$data = $row['session_data'];
}
return $data;
}
function write( $id, $data ) {
$time = time() + $this->life_time;
global $conn;
$newid = $id;
$newdata = $data;
$sql = "SELECT session_id FROM session_tmp WHERE session_id = ?"; // error happen here!!!!
$q = $conn->prepare($sql);
$result = $q->execute(array($newid));
return TRUE;
}
}
に追加global $conn;
するfunction read()
と、エラーが修正されます。global $conn;
でエラーを修正できない理由がわかりませんfunction write()
。エラーを修正するには?