- //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配置外的数据库(临时数据库等)

![[手游] 三网H5小游戏【少年仙路】WIN系服务端+Linux手工服务端+详细搭建教程](https://cdn.jxasp.com:9143/image/20260615/136BC33AA47EB0D84E878835A8B38FDB.png)

















