thinkphp implementation of the session to the MySQL method

Source: Internet
Author: User

First set in index.php to:

<?php
Define (' App_debug ', true);//set to debug mode
Require '. /thinkphp/thinkphp.php ';//Set the entry file
Ini_set ("Session.save_handler", "user");//Set PHP session by user-defined



Set in config.php to:

<?php
return Array (//' configuration item ' = ' config value ')
Add a database configuration letter
' Show_page_trace ' =>true,
' Db_type ' = ' mysql ',//database type
' db_host ' = ' localhost ',//server address
' Db_name ' = ' thinkphp ',//database name
' Db_user ' = ' Your user name ',//user name
' Db_pwd ' = ' Your password ',//password
' Db_port ' = 3306,//Port
' Db_prefix ' = ' think_ ',//database table prefix suffix
' Session_options ' =>array (
' Type ' = ' db ',//session with database save
' Expire ' =>1440,//session expiration time, if not set is the default value in PHP.ini
),
' session_table ' = ' think_session ',//must be set to this, if you do not add a prefix to find the data table, this need to note
);
?>


The database settings use the DDL in SessionDb.class.php, but the Engine=myisam DEFAULT Charset=utf8 is added later

CREATE TABLE Think_session (
session_id varchar (255) is not NULL,
Session_expire Int (one) is 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

Session (' Session_name ', ' Session_value ')


Article reprinted from The Home Management house: http://www.bitscn.com/pdb/php/201408/305909.html

thinkphp implementation of the session to the MySQL method

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.