<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
class Index extends Controller
{
public function index()
{
# 使用sql语句的方式查询
//$res = Db::query("select * from imooc_user where id=?", [1]);
// $res = Db::execute("insert into imooc_user set username=?,password=?,email=?", [
// 'imooc',
// md5('imooc'),
// 'imooc@qq.com'
// ]);
# select 返回所有记录 返回的结果是一个二维数组
# 如果结果不存在,返回一个空数组
//$res = Db::table('imooc_user')->select();
# find 返回一条记录 返回的是一个一维数组 如果没有设置条件 默认返回id最小的一条
# 如果结果不存在 返回NULL
//$res = Db::table('imooc_user')->find();
# value 返回一条记录 并且是这条记录的某个字段值
# 如果结果不存在 返回NULL
//$res = Db::table('imooc_user')->value('username');
# column 返回一个一维数组 数组中的value值就是我们要获取的列的值
# 如果存在第二个参数 就返回数组并且用第二个参数的值作为数组的key值
# 如果结果不存在 返回空数组
//$res = Db::table('imooc_user')->column('username', 'email');
//$res = Db::name('user')->select();
$res = db('user', [], false)->select();
dump($res);
}
}
?>