abstract:<?phpnamespace app\index\controller;use think\Collection;use think\Db;use think\db\Query;class Test1 extends Collection{ //數(shù)據(jù)庫連接測試 靜態(tài)連接,動態(tài)連接,環(huán)境變量連接,模型連接 public function de
<?php
namespace app\index\controller;
use think\Collection;
use think\Db;
use think\db\Query;
class Test1 extends Collection
{
//數(shù)據(jù)庫連接測試 靜態(tài)連接,動態(tài)連接,環(huán)境變量連接,模型連接
public function demo1(){
//靜態(tài)連接 database.php
$res=Db::table('staff')->limit(1)->select();
//動態(tài)連接 database.php 'my_db'
$res=Db::connect('my_db')
->table('staff')
->limit(2)
->select();
//環(huán)境變量 類似用戶自定義的全局變量,一次定義,都能用,定義.env文件
$res=Db::table('staff')->limit(3)->select();
//模型連接
$res=\app\index\model\Staff::limit(4)->select();
dump($res);
}
Correcting teacher:天蓬老師Correction time:2019-03-22 13:40:34
Teacher's summary:解答正確 , 如果是自己全程自己想著寫的, 就非常厲害了