您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

保存SESSION到SQLITE,

2024/3/26 9:11:02发布11次查看
保存session到sqlite save session thinkphp ?php/** * sqlite保存session * @author weaksun 52132522@qq.com */namespace think\session\driver;use sessionhandlerinterface;use pdo;class sqlite implements sessionhandlerinterface {static protected $
保存session到sqlite save session thinkphp true)); empty($iscreate) && $this->exec(pragma encoding = 'utf8';pragma temp_store = 2;pragma auto_vacuum = 0;pragma count_changes = 1;pragma cache_size = 9000;); $this->chktable() || $this->createtable(); } } /** * 创建sessionid * @return string */ public function create_sid() { return uniqid(sprintf('%08x', mt_rand(0, 2147483647))); } /** * 打开session * @param string $path * @param string $name * @return boolean */ public function open($path, $name) { return is_object(static::$handler); } /** * 关闭session * @return boolean */ public function close() { return true; } /** * 读取session * @param string $id * @return string */ public function read($id = null) { $table = static::$tablenamename; $sth = static::$handler->query(select `value` from `{$table}` where `id`='{$id}' and `expire` > strftime('%s','now') limit 1, pdo::fetch_num); if (!empty($sth)) { list($data) = $sth->fetch(); unset($sth); } else { $data = ''; } return $data; } /** * 写入session * @param string $id * @param string $data * @return integer */ public function write($id = null, $data = null) { $table = static::$tablenamename; $expire = ceil(static::$expire + static::$nowtime); return $this->exec(replace into `{$table}` values('{$id}','{$data}',{$expire})); } /** * 销毁session * @param string $id * @return integer */ public function destroy($id = 0) { $table = static::$tablenamename; return $this->exec(delete from `{$table}` where `id` = '{$id}'); } /** * 垃圾回收 * @param string $expire * @return integer */ public function gc($expire = 0) { $table = static::$tablenamename; return $this->exec(delete from `{$table}` where `expire` gettables()); } /** * 获取当前数据库的数据表列表 * @return array 返回获取到的数据表列表数组 */ protected function gettables() { $tables = $data = array(); $sth = $this->query(select `name` from `sqlite_master` where `type` = 'table' union all select `name` from `sqlite_temp_master`); if (!empty($sth)) { while ($row = $sth->fetch(pdo::fetch_num, pdo::fetch_ori_next)) { $tables[] = $row[0]; } unset($sth, $row); } return $tables; } /** * 创建当前数据表 * @return integer 成功返回1,失败返回0 */ protected function createtable() { $tablename = static::$tablenamename; return $this->exec(create table if not exists `{$tablename}` (`id` varchar primary key on conflict fail not null collate 'nocase',`value` text not null,`expire` integer not null);); } public function __call($method, $arguments) { if (method_exists(self::$handler, $method)) { return call_user_func_array(array(self::$handler, $method), $arguments); } else { e(__class__ . ':' . $method . l('_method_not_exist_')); return; } }}
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product