thinkphp Session DB Configuration

Source: Internet
Author: User

This article mainly introduces the thinkphp implementation of the session into the MySQL method, the need for friends can refer to the next

In this paper, an example is given to illustrate the thinkphp implementation of the session to the MySQL method, the operating environment is ThinkPHP3.1.2 version

First set in index.php to:

?
1234 <?phpdefine(‘APP_DEBUG‘, true);//设置为调试模式require‘../ThinkPHP/ThinkPHP.php‘;//设置入口文件ini_set("session.save_handler", "user");//设置PHP的SESSION由用户定义

Set in config.php to:

?
123456789101112131415161718 <?phpreturn 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 settings use the DDL in SessionDb.class.php, but the Engine=myisam DEFAULT Charset=utf8 is added later

?
123456 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 visit your index.php and find the Think_session table in phpMyAdmin, we will be pleasantly surprised to find a lot of data.
This problem is done. Do not set the other, SessionDb.class.php will automatically load.

So the thinkphp call

?
1 session(‘session_name‘,‘session_value‘)

The system will automatically store this session in the database created above.

Note: Pro-test is feasible

thinkphp Session DB Configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.