Destoon secondary development common database operations

Source: Internet
Author: User
This article mainly introduces common database operations for destoon secondary development. For more information, see destoon. after the system is initialized, the system automatically connects to the database and stores the database operation objects in $ db. For database operation methods, see The include/db_mysql.class.php function prototype. Examples of common database operations are given below.

1. execute SQL statements

$db->query("INSERT INTO `{$DT_PRE}table` (`xxx`) VALUES ('yyy')");
$db->query("UPDATE `{$DT_PRE}table` SET `xxx`='yyy' WHERE `zzz`=1");
$db->query("DELETE FROM `{$DT_PRE}table` WHERE `zzz`=1");


2. read multiple messages

$A = array();$result = $db->query("SELECT * FROM `{$DT_PRE}table` WHERE `xxx`='yyy' ORDER BY `zzz` DESC LIMIT 0,10");while($r = $db->fetch_array($result)) {  $A[] = $r;}print_r($A);

3. read a single message

$A = $db->get_one("SELECT * FROM `{$DT_PRE}table` WHERE `xxx`='yyy'");print_r($A);

4. total number of computations

$A = $db->get_one("SELECT COUNT(*) AS num FROM `{$DT_PRE}table` WHERE `xxx`='yyy'");echo $A['num'];

The system table prefix can use the variable $ DT_PRE (usually used in statements) or $ db-> pre (usually used in functions ).
If you use database operations in a function, you must first perform global $ db;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.