Home >php教程 >php手册 >thinkphp 5 multiple database connection

thinkphp 5 multiple database connection

WBOY
WBOYOriginal
2016-07-06 13:29:171017browse

I recently worked on a project that required connecting to multiple databases. I read the distributed database in the manual. After setting it up according to the above, I was still a little confused about what to do next. Then I guessed the next way of writing based on the manual to connect to the database and successfully add data, but I don’t know how to do it. If there are any problems with the writing, please ask the experts for guidance
    // database.php 中配置   主要修改这两项配置<br> <br>     // 数据库名  'database'    => '默认数据库的名称,第二个数据库的名称',<br>    'database'    => 'a,b',<br> <br>     // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)<br>     'deploy'      => 1,<br> <br>     详细配置参考手册<br>     http://www.kancloud.cn/manual/thinkphp5/118061<br> <br>     public function books(){<br>         $data['donor_name'] = 'haha';<br>         $data['donor_phone'] = '254658785545';<br> <br>         self::much('donor')->insert($data);<br>     }<br> <br>     //$db  第二个数据库的名称     $table  表名称<br>     protected function much($table,$db='b.'){<br>        return Db::table($db.$table);<br>     }

Yunqi Conference Beijing Station: It is rare for Alibaba technical experts to appear on the scene. This time, more than 100 people came? !

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