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');