thinkphp6 动态连接数据库

猿掌柜
2022-07-19 / 1 评论 / 7 阅读 / 正在检测是否收录...
//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');
1

评论

博主关闭了当前页面的评论