tp5配置多数据库


tinkphp5配置多数据库以及Db切库和模型切库

database.php

return [ 'd1'=>[ // 数据库类型 'type' => 'mysql', // 服务器地址 'hostname' => '127.0.0.1', // 数据库名 'database' => 'd1', // 用户名 'username' => 'root', // 密码 'password' => 'root', // 端口 'hostport' => '3306', ], 'd2'=>[ // 数据库类型 'type' => 'mysql', // 服务器地址 'hostname' => '127.0.0.1', // 数据库名 'database' => 'd2', // 用户名 'username' => 'root', // 密码 'password' => 'root', // 端口 'hostport' => '3306', ] ]; 

 

Model:

protected function initialize() { parent::initialize(); $this->connection = 'database.d2'; } 

Controller:

Db::connect('database.d2')->table('user')->find();


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM