Commonly used database operations in destoon secondary development_PHP tutorial

WBOY
Release: 2016-07-13 10:24:26
Original
887 people have browsed it

After destoon initializes the system, the system will automatically connect to the database and save the database operation object in $db. For database operation methods, please refer to the include/db_mysql.class.php function prototype. Examples of common database operations are given below.

1. Execute SQL statement

$db->query("INSERT INTO `{$DT_PRE}table` (`xxx`) VALUES ('yyy')");

Copy after login
$db->query("UPDATE `{$DT_PRE}table` SET `xxx`='yyy' WHERE `zzz`=1");

Copy after login
$db->query("DELETE FROM `{$DT_PRE}table` WHERE `zzz`=1");

Copy after login


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);

Copy after login

3. Read a single message

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

Copy after login

4. Calculate the total number

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

Copy after login

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825480.htmlTechArticledestoon After initializing the system, the system will automatically connect to the database and save the database operation object in $db. For database operation methods, please refer to the include/db_mysql.class.php function prototype, below...
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