Home  >  Article  >  Backend Development  >  How to connect multiple databases through thinkphp

How to connect multiple databases through thinkphp

jacklove
jackloveOriginal
2018-06-15 11:26:432346browse

thinkphp connects to multiple databases
In the configuration file:

return array(    //数据库配置信息 默认连接这一个
    'DB_TYPE' => 'mysql', // 数据库类型
    'DB_HOST' => '127.0.0.1', // 服务器地址
    'DB_NAME' => 'test1', // 数据库名
    'DB_USER' => 'root', // 用户名
    'DB_PWD' => '', // 密码
    'DB_PORT' => 3306, // 端口
    'DB_PREFIX' => '', // 数据库表前缀
    'DB_CHARSET'=> 'utf8', // 字符集
    'LOAD_EXT_FILE'=>'functions',    //我的第一个数据库连接
    'DB_BBS'=>array(    'dbms' => 'mysql',    'username' => 'root',    'password' => '',    'hostname' => '127.0.0.1',    'hostport' => '3306',    'database' => 'test1'
    ),    //第二个数据库链接,
    'DB_NEWS'=>array(    'dbms'=>'mysql',    'username'=>'root',    'password'=>'',    'hostname'=>'127.0.0.1',    'hostport'=>'3306',    'database'=>'test2'
    )
);

Operations to interact with the database:
When instantiating the table
The dot in front is the database name, and the dot is the table Name

$user=M('test2.user');

This article explains how to connect multiple databases through thinkphp. For more related content, please pay attention to the php Chinese website.

Related recommendations:

About ThinkPHP 5. Some basic operations of the database

Rules for adding different data in thinkphp5

About the related operations of ThinkPHP5 database

About the database and model usage of ThinkPHP5

The above is the detailed content of How to connect multiple databases through thinkphp. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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