Home > PHP Framework > ThinkPHP > How to configure ThinkPHP files

How to configure ThinkPHP files

王林
Release: 2023-05-28 18:40:06
forward
1555 people have browsed it

1. The common configuration method is Add the following configuration parameters in database.php under the application directory or module directory:

return [
 
  // 数据库类型  'type' => 'mysql',
 
  // 数据库连接DSN配置  'dsn' => '',
 
  // 服务器地址  'hostname' => '127.0.0.1',
 
  // 数据库名  'database' => 'thinkphp',
 
  // 数据库用户名  'username' => 'root',
 
  // 数据库密码  'password' => '',
 
  // 数据库连接端口  'hostport' => '',
 
  // 数据库连接参数  'params' => [],
 
  // 数据库编码默认采用utf8  'charset' => 'utf8',
 
  // 数据库表前缀  'prefix' => 'think_',
 
  // 数据库调试模式  'debug' => false,
 
  // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)  'deploy' => 0,
 
  // 数据库读写是否分离 主从式有效  'rw_separate' => false,
 
  // 读写分离后 主服务器数量  'master_num' => 1,
 
  // 指定从服务器序号  'slave_no' => '',
 
// 是否严格检查字段是否存在  'fields_strict' => true,];
Copy after login

2.type The parameter supports the complete definition of the namespace . If there is no namespace definition, \think\db\connector is used as the namespace by default. If you use the database driver that applies your own extension, it can be configured as:

// 数据库类型
 
'type' => '\org\db\Mysql',
Copy after login

means The database connector uses the \org\db\Mysql class as the database connection driver instead of the default \think\db\connector\Mysql.

3. Each module can set independent database connection parameters, and the same configuration parameters do not need to be set repeatedly. For example, we can define it in the database.php configuration file of the admin module:

return [
 
  // 服务器地址  
 
  'hostname' => '192.168.1.100',
 
  // 数据库名  
 
'database' => 'admin',];
Copy after login

means that the database address of the admin module is changed to 192.168.1.100, the database name is changed to admin, and other connection parameters are the same as the configuration in the application's database.php.

The above is the detailed content of How to configure ThinkPHP files. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template