使用前提:

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);
?>
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。