Home > Backend Development > PHP Tutorial > How to connect multiple databases through thinkphp

How to connect multiple databases through thinkphp

jacklove
Release: 2023-04-01 09:34:02
Original
2391 people have browsed it

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'
    )
);
Copy after login

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');
Copy after login

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!

Related labels:
source:php.cn
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