URL_JSON番外篇

Original 2019-03-22 13:13:13 189
abstract:<?phpnamespace app\index\controller;use think\Collection;use think\Db;use think\db\Query;class Test1 extends Collection{    //数据库连接测试 静态连接,动态连接,环境变量连接,模型连接    public function de

<?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);
   }

Correcting teacher:天蓬老师Correction time:2019-03-22 13:40:34
Teacher's summary:解答正确 , 如果是自己全程自己想着写的, 就非常厉害了

Release Notes

Popular Entries