参考
我只是个搬运工, 一个探路者, 这个不是我写的, 原作者在这里
为什么有这样的需求? ...鬼知道为什么不存memcache或者redis,鬼知道你会遇到什么样的需求, 那还能怎么办,自己解决呗,为了避免下次再一顿百度..一顿谷歌...我就记录一下
建立对应的数据表
CREATE TABLE think_session (
session_id varchar(255) NOT NULL,
session_expire int(11) UNSIGNED NOT NULL,
session_data blob,
UNIQUE KEY `session_id` (`session_id`)
);
建立数据库驱动扩展类 /extend/driver/session/Mysql.php
默认没有这些目录和文件, 手动创建吧...
<?php
namespace driver\session;
use SessionHandler;
use think\Db;
use think\Config;
use think\Exception;
/**
* Class Mysql
* session 数据库驱动
* @package driver\session
*/
class Mysql extends SessionHandler
{
protected $handler = null;
protected $table_name = null;
protected $config = [
'session_expire' => 3600, // Session有效期 单位:秒
'session_prefix' => 'think_', // Session前缀
'table_name' => 'session', // 表名(不包含表前缀)
];
protected $database = [
'type' => 'mysql', // 数据库类型
'hostname' =>