Home >PHP Framework >ThinkPHP >Native MySql statements in TP6
TP6
encapsulates many methods for MySql
database operations, but many people are still accustomed to using SQL# directly ## statement is used to operate the database. This article will take you to take a look.
Prerequisites for use:
ThinkPHP6 Database and model operations have been independently
ThinkORMLibrary
think\facade\Db) to call
Introduction class:
use think\facade\Db;
1.query method is used to perform
MySql query operations
<?php $sql="SELECT * FROM `shop_goods` where status=1"; $query = Db::query($sql); print_r($query); ?>
2.execute method is used to perform
MySql new and modified operations
<?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); ?>
Recommendation: 《Thinkphp6》《PHP Video Tutorial》《The latest 10 thinkphp video tutorial recommendations》
The above is the detailed content of Native MySql statements in TP6. For more information, please follow other related articles on the PHP Chinese website!