tp6动态连接数据库

使用场景

tp6连接除database.php配置外的数据库(临时数据库等)

使用方式

//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');
上一篇:2021-10-12


下一篇:java配置环境及安装