thinkphp6 动态连接数据库

thinkphp6 动态连接数据库

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

评论 (1)

取消
  1. 头像
    happy
    Windows 10 · Google Chrome

    有用

    回复