Destoon two times to develop common database operation _php instance

Source: Internet
Author: User
Tags function prototype

Destoon the system automatically connects the database after the system is initialized and saves the database operations object to $DB. For database operation methods please refer to the Include/db_mysql.class.php function prototype, the following examples of common database operations.

1. Execute SQL statement

$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 more information

$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, the total number of calculations

$A = $db->get_one ("Select COUNT (*) as num from ' {$DT _pre}table ' WHERE ' xxx ' = ' yyy '");
echo $A [' num '];

The system's table prefixes can be used in variable $dt_pre (commonly used in statements) or $db->pre (commonly used in functions).
If you use database operations in a function, you need to first perform a 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.