tp5連接多個數據庫

config.php中中定義db2:
在這裏插入圖片描述
控制器中打印一下:

<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Request;
class Index extends Controller
{
    public function index()
    {
    	//連接默認的數據庫
    	$db1=Db::name('users')
    		->select();

    	//連接定義的第二個數據庫
        $db2=Db::connect('db2');
        $result=$db2->name('ceshi')->select();
        print_r($result);die;
        return view('index');
    }
}

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章