tp6
中封装了很多对<a style="color:#f60; text-decoration:underline;" href="https://www.php.cn/zt/15713.html" target="_blank">mysql</a>
数据库操作的方法,但是还是有很多人习惯使用直接使用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语句的详细内容,更多请关注php中文网其它相关文章!
Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号