Home >PHP Framework >ThinkPHP >Native MySql statements in TP6

Native MySql statements in TP6

autoload
autoloadOriginal
2021-03-30 16:31:004249browse

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

Required When using the Db class, you must use the facade method (

think\facade\Db) to call

Unified entrance for database operations: Db::

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`=&#39;1100&#39; 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn