tp6动态连接数据库(连接除database.php配置外的数据库(临时数据库等))
//use think\facade\Config;$config = Config::get('database');$config['connections']['tmp'] = ['type'=> 'mysql','hostname'=> 'localhost','database'=> 'test','username'=> 'root','password'=&.
·
//use think\facade\Config;
$config = Config::get('database');
$config['connections']['tmp'] = [
'type' => 'mysql',
'hostname' => 'localhost',
'database' => 'test',
'username' => 'root',
'password' => 'root',
'hostport' => 3306,
'params' => [],
'charset' => 'utf8mb4'
];
Config::set($config, 'database');
Db::connect('tmp')->query('select * from t limit 1');
使用场景
tp6连接除database.php配置外的数据库(临时数据库等)
更多推荐
已为社区贡献5条内容
所有评论(0)