Db::connect('mysql://root:1234@127.0.0.1:3306/thinkphp#utf8'); |
Db::connect([ // 数据库类型 'type' => 'mysql', // 数据库连接DSN配置 'dsn' => '', // 服务器地址 'hostname' => '127.0.0.1', // 数据库名 'database' => 'thinkphp', // 数据库用户名 'username' => 'root', // 数据库密码 'password' => '', // 数据库连接端口 'hostport' => '', // 数据库连接参数 'params' => [], // 数据库编码默认采用utf8 'charset' => 'utf8', // 数据库表前缀 'prefix' => 'think_', ]); |
'database1' => []//数据库配置数组 'database2' => []//数据库配置数组 |
$db = Db::connect("database1"); $db->name("table")->select(); |
select * from database1.table1 as t1 inner join database2.table2 as t2 where t1,id=t2.id |