小兔网

TP6中的原生MySql语句-ThinkPHP

TP6中封装了很多对MySql数据库操作的方法,但是还是有很多人习惯使用直接使用SQL语句,对数据库进行操作,本文就带大家一起来看一看。

使用前提:

ThinkPHP6 数据库和模型操作已经独立为ThinkORM

要使用Db类必须使用门面方式( think\facade\Db )调用

数据库操作统一入口: Db::

引入类:

use think\facade\Db;

1.query 方法用于执行 MySql 查询操作

<?php$sql="SELECT * FROM `shop_goods` where status=1";$query = Db::query($sql);print_r($query);?>

2.execute 方法用于执行 MySql 新增和修改操作

<?php    $execute = Db::execute("INSERT INTO `shop_goods` VALUES (3, 1)");    print_r($execute);    $execute = Db::execute("UPDATE `shop_goods` set `price`='1100' where `id`=3 ");    print_r($execute);?>

推荐:Thinkphp6》《PHP视频教程》《最新的10个thinkphp视频教程推荐

以上就是TP6中的原生MySql语句的知识。速戳>>知识兔学习精品课!