First, the index.php is set to:
<?php define('APP_DEBUG', true);//设置为调试模式 require '../ThinkPHP/ThinkPHP.php';//设置入口文件 ini_set("session.save_handler", "user");//设置PHP的SESSION由用户定义
The config.php is set to:
<?php return array(//'配置项'=>'配置值' // 添加数据库配置信 'SHOW_PAGE_TRACE' =>true, 'DB_TYPE' => 'mysql', // 数据库类型 'DB_HOST' => 'localhost', // 服务器地址 'DB_NAME' => 'thinkphp', // 数据库名 'DB_USER' => '你的用户名', // 用户名 'DB_PWD' => '你的密码', // 密码 'DB_PORT' => 3306, // 端口 'DB_PREFIX' => 'think_', // 数据库表前缀缀 'SESSION_OPTIONS'=>array( 'type'=> 'db',//session采用数据库保存 'expire'=>1440,//session过期时间,如果不设就是php.ini中设置的默认值 ), 'SESSION_TABLE'=>'think_session', //必须设置成这样,如果不加前缀就找不到数据表,这个需要注意 ); ?>
The database setting uses the DDL in SessionDb.class.php, but ENGINE=MyISAM DEFAULT CHARSET=utf8
CREATE TABLE think_session ( session_id varchar(255) NOT NULL, session_expire int(11) NOT NULL, session_data blob, UNIQUE KEY `session_id` (`session_id`) )ENGINE=MyISAM DEFAULT CHARSET=utf8;
Now access your index.php and then find the think_session table in phpmyadmin. We will be surprised to find that there is more data.
This problem is solved. Do not set anything else, SessionDb.class.php will be loaded automatically.
In this way, the ThinkPHP call
session('session_name','session_value')
system will automatically store this session in the database created above.
Recommended related articles : The most complete collection of js interview questions in 2020 (latest)