关于tp6.0 原生sql查询操作

V6.0.3+版本开始,原生查询仅支持Db类操作,不支持在模型中调用原生查询方法(包括queryexecute方法)。

query方法用于执行SQL查询操作,返回查询结果数据集(数组)。

执行:
Db::query("select * from edu_wx_classes_stu where id=? AND stu_id=?", [178, 127]);//参数绑定

对应的sql语句为

select * from edu_wx_classes_stu where id=178 AND stu_id=127

execute用于更新和写入数据的sql操作,如果数据非法或者查询错误则返回false,否则返回影响的记录数。

执行:

 Db::execute("update edu_wx_classes_stu set remark=:name where id=:status", ['name' => 'thinkphp', 'status' => 178]);  //命名绑定

对应的sql语句为

update edu_wx_classes_stu set remark='thinkphp' where id=178

你可能感兴趣的:(sql,数据库,php)