一 首先连接数据库
将根目录 .example.env 改名为 .env
APP_DEBUG = true
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1
DATABASE = news
USERNAME = root
PASSWORD = root
HOSTPORT = 3306
CHARSET = utf8
DEBUG = true
[LANG]
default_lang = zh-cn
主要设置此处 此外 config 下database可以配置
二 模型使用
新建模型 命名为article_21 和表名一致
namespace app\index\model;
use think\model;
use think\facade\Db;
/**
*
*/
class Article_21 extends model
{
public function index(){
$list = DB::name("article_21")->limit(10)->select();
return $list;
}
}
模型使用
namespace app\index\controller;
use think\facade\View;
use think\facade\Db;
use app\Request;
use app\index\model\Article_21;
class Article{
public function index(Request $request){
$data = $request->param();
halt($data);
$articelModel = new Article_21();
$list = $articelModel->where(['itemid'=>288])->find();
halt($list);
}
}