コード例 #1
0
                $stmt = self::$pdo->prepare($sql);
                $stmt->execute(array($data, self::$ctime, $sid));
            }
            //如果没有数据,就新插入一条数据
        } else {
            if (!empty($data)) {
                $sql = "insert into session(sid, sdata, utime, uip, uagent) values(?, ?, ?, ?, ?)";
                $stmt = self::$pdo->prepare($sql);
                $stmt->execute(array($sid, $data, self::$ctime, self::$uip, self::$uagent));
            }
        }
    }
    //销毁 session_destroy()
    public static function destroy($sid)
    {
        $sql = "delete from session where sid=?";
        $stmt = self::$pdo->prepare($sql);
        return $stmt->execute(array($sid));
    }
    //回收垃圾
    public static function gc($maxlifetime)
    {
        //	utime < ctime - self::$maxlifetime
        $sql = "delete from session where utime < ?";
        $stmt = self::$pdo->prepare($sql);
        return $stmt->execute(array(self::$ctime - self::$maxlifetime));
    }
}
//开启
DBSession::start($pdo);