How to use the database class provided by the CMS

Source: Internet
Author: User

E/class/db_ SQL .php encapsulates an SQL statement. Using the class library of the program can bring convenience and efficiency to our development, and reduce the number of files added.

First, make the following preparations:

  1. Create a test directory under the e directory, for example, e/trylife/td-test/
  2. Create a PHP file under the directory in 1, for example, I created e/trylife/td/test-db_ SQL .php
  3. Write the following code into the file:
<? Php/* reference file */include (".. /.. /class/connect. php "); include (".. /.. /class/db_ SQL .php ");/* Create a database link and instantiate a class */$ link = db_connect (); $ empire = new mysqlquery (); /* the center of this location is used for our test code * // * closes the database connection and releases class */db_close (); $ empire = null;?>
First test object: query
  1. Query () executes mysql_query ()
  2. The returned value also follows the explanation of mysql_query () in the PHP manual. However, if the execution fails, the returned value is different from that of mysq_query.
  3. The test code is as follows (remove the comments with a relatively large length ):
<? Php include (".. /.. /class/connect. php "); include (".. /.. /class/db_ SQL .php "); $ link = db_connect (); $ empire = new mysqlquery (); function hr () {echo ' 

The Source Text of the query object is as follows: In the ninth row of e/class/db_ SQL .php; view the PHP manual for die () and interpret it as "die () function to output a message and exit the current script "; therefore, the var_dump () and its hr () in the third test statement exit if they are not executed;

function query($query)  {      $this->sql=mysql_query($query) or die(mysql_error().''.str_replace($GLOBALS['dbtbpre'],'***_',$query));      return $this->sql;  }  
The second test object: query1

The object query1 is the same as mysql_query (). To save the layout duration, all Chinese characters are deleted.

<? Php include (".. /.. /class/connect. php "); include (".. /.. /class/db_ SQL .php "); $ link = db_connect (); $ empire = new mysqlquery (); function hr () {echo '

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.