Home  >  Article  >  php教程  >  thinkphp 5 多数据库 连接

thinkphp 5 多数据库 连接

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

最近做项目 需要连接多个数据库,看了下手册里面的分布式数据库,按照上面设置完了 后面怎么做 还是有点懵 然后根据手册 猜想了下 一种写法 可以连接数据库并成功添加数据 可是不知道这种写法 有没有什么问题 还望大神 指点
    // 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>     }

云栖大会北京站:阿里技术专家难得出镜,这次一下来了100多位?!

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