cms可以连接多个数据库操作
1、改配置文件config/database.php
<?php
// default是迅睿cms系统库
$db['default'] = [
'hostname' => '127.0.0.1',
'username' => 'xunruicms',
'password' => 'xunruicms',
'database' => 'xunruicms',
'DBPrefix' => 'dr_',
];
// test是我们连接的第二个数据库
$db['test'] = array(
'hostname' => '127.0.0.1',
'username' => 'xunruicms2',
'password' => 'xunruicms2',
'database' => 'xunruicms2',
'DBPrefix' => 'dr_',
);
2、程序中调用test数据库的写法
$db = \Config\Database::connect('test', false); // 连接数据库
// 查询数据库
$db->query('YOUR QUERY HERE');
$db->close(); // 关闭连接