使用前提:
ThinkPHP6
數(shù)據(jù)庫(kù)和模型操作已經(jīng)獨(dú)立為ThinkORM
庫(kù)
要使用Db類必須使用門面方式( thinkfacadeDb
)調(diào)用
數(shù)據(jù)庫(kù)操作統(tǒng)一入口: Db::
引入類:
use thinkfacadeDb;
1.query
方法用于執(zhí)行 MySql
查詢操作
<?php $sql="SELECT * FROM `shop_goods` where status=1"; $query = Db::query($sql); print_r($query); ?>
2.execute
方法用于執(zhí)行 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個(gè)thinkphp視頻教程推薦》