Home > PHP Framework > ThinkPHP > body text

Native MySql statements in TP6

autoload
Release: 2021-04-15 14:05:12
Original
4222 people have browsed it

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;
Copy after login

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);
?>
Copy after login

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);
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template