前言[随时更新]
MySQL快速复习
MySQL原生查询
选择数据表
删除数据
聚合查询
时间查询
视图查询
子查询
总结/参考
文件位置:/application/database.php
以MySQL为例,主要修改以下配置项,即可完成与数据库的连接
database.php文件中,需要设置的部分如下:
// 服务器地址
'hostname' => 'localhost',
// 数据库名
'database' => 'tp5',
// 用户名
'username' => 'root',
// 密码
'password' => 'root',
// 数据库编码默认采用utf8
'charset' => 'utf8',
// 数据库表前缀
'prefix' => 'tp5_',
<?php
namespace app\index\controller;
use think\Db;
use think\Debug;
class Index{
public function index(){
Debug::dump(Db::table('tp5_staff')->select());
}
}
tp5.com/index/index/index 运行结果如下: