方法一:
1.引入use think\Db;
2.查詢資料語句:$rs=Db::name('school')->select();列出所有資料
例子:
<?php
namespace app\admin\controller;
use think\Controller;
use think\Validate;
use think\Request;
use think\Db;
class Main extends controller
{
public function index()
{
return $this -> fetch();
}
//學校清單
public function school()
{
//$rs=db('school')->select();
$rs=Db::name('school')->select();
dump($rs);die;
return $this -> fetch();
}
方法二:助手函數
直接使用查詢語句$rs=db('school')->select();
例子:
<?php
namespace app\admin\controller;
use think\Controller;
use think\Validate;
use think\Request;
//use think\Db;
class Main extends controller
{
public function index()
{
return $this -> fetch();
}
//學校清單
public function school()
{
$rs=db('school')->select();
//$rs=Db::name('school')->select();
dump($rs);die;
return $this -> fetch();
}