<?php
namespace app\index\controller;
use think\Collection;
use think\Db;
use think\db\Query;
class Test1 extends Collection
{
//数据库连接测试 静态连接,动态连接,环境变量连接,模型连接
public function demo1(){
//静态连接 database.php
$res=Db::table('staff')->limit(1)->select();
//动态连接 database.php 'my_db'
$res=Db::connect('my_db')
->table('staff')
->limit(2)
->select();
//环境变量 类似用户自定义的全局变量,一次定义,都能用,定义.env文件
$res=Db::table('staff')->limit(3)->select();
//模型连接
$res=\app\index\model\Staff::limit(4)->select();
dump($res);
}