欠采样欠采样
Db类支持原生SQL查询操作,主要包括下面两个方法:
query方法
query方法用于执行SQL查询操作,和select方法一样返回查询结果数据集(数组)。
使用示例:Db::query("select * from think_user where status=1");
如果希望从主库读取,可以使用Db::master(true)->query("select * from think_user where status=1");
新版的query方法可以支持的链式操作方法包括:
链式方法说明cache查询缓存
master是否主库查询(分布式有效)
procedure存储过程查询
execute方法
execute用于更新和写入数据的sql操作,如果数据非法或者查询错误则返回false,否则返回影响的记录数。
使用示例:Db::execute("update think_user set name='thinkphp' where status=1");
参数绑定
支持在原生查询的时候使用参数绑定,包括问号占位符或者命名占位符,例如:Db::query("select * from think_user where id=? AND status=?", [8, 1]);
// 命名绑定
Db::execute("update think_user set name=:name where status=:status", ['name' => 'thinkphp', 'status' => 1]);
任务
?不会了怎么办