Thinkphp3.2.3 多数据库配置

xiaoxiao2021-02-28  117

Thinkphp3.2.3 多数据库配置

同时需要连接多个数据库时,配置及使用方法。

return array( //'配置项'=>'配置值' 配置一个默认的数据库,和一个叫model2的数据库 'DB_DSN' => 'mysql://root:123456@192.168.3.237:3306/test', 'model2' => array('DB_TYPE' => 'mysql', // 数据库类型 'DB_HOST' => '192.168.3.237', // 服务器地址 'DB_NAME' => 'test1', // 数据库名 'DB_USER' => 'root', // 用户名 'DB_PWD' => '123465', // 密码 'DB_PORT' => 3306, // 端口 'DB_CHARSET' => 'utf8', // 字符集 ), );

在控制器中调用的方式为

//调用默认的数据库中的表 $m = M('file'); //调用model2数据库中的表 $file = M('file','','model2');
转载请注明原文地址: https://www.6miu.com/read-49083.html

最新回复(0)