ThinkPHP implements the method of storing SESSION in MYSQL
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)

The article discusses ThinkPHP's built-in testing framework, highlighting its key features like unit and integration testing, and how it enhances application reliability through early bug detection and improved code quality.

Article discusses using ThinkPHP for real-time stock market data feeds, focusing on setup, data accuracy, optimization, and security measures.

The article discusses key considerations for using ThinkPHP in serverless architectures, focusing on performance optimization, stateless design, and security. It highlights benefits like cost efficiency and scalability, but also addresses challenges

The article discusses implementing service discovery and load balancing in ThinkPHP microservices, focusing on setup, best practices, integration methods, and recommended tools.[159 characters]

ThinkPHP's IoC container offers advanced features like lazy loading, contextual binding, and method injection for efficient dependency management in PHP apps.Character count: 159

The article discusses using ThinkPHP to build real-time collaboration tools, focusing on setup, WebSocket integration, and security best practices.

ThinkPHP benefits SaaS apps with its lightweight design, MVC architecture, and extensibility. It enhances scalability, speeds development, and improves security through various features.

The article outlines building a distributed task queue system using ThinkPHP and RabbitMQ, focusing on installation, configuration, task management, and scalability. Key issues include ensuring high availability, avoiding common pitfalls like imprope


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version