搜索

URL_JSON番外篇

原创 2019-03-22 13:13:13 275
摘要:<?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);
   }

批改老师:天蓬老师批改时间:2019-03-22 13:40:34
老师总结:解答正确 , 如果是自己全程自己想着写的, 就非常厉害了

发布手记

热门词条