How to use the database class provided by the Empire CMS _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
How to use the database class that comes with the CMS. The CMS encapsulates an SQL statement in eclassdb_ SQL .php. using the class library of the program can bring convenience and efficiency to our development, and reduce the number of files added. 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:
   
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 ):
 ';}$ SQL = $ empire-> query ("select id, title from {$ dbtbpre} ecms_news"); var_dump ($ SQL); hr (); // if the statement is successfully executed, true $ SQL = $ empire-> query ("UPDATE {$ dbtbpre} ecms_news set title = 'title' where id = 1") is returned "); var_dump ($ SQL); hr (); // if the statement fails to be executed, terminate the execution and return the error statement. the following statement uses a non-existent field $ SQL = $ empire-> query ("UPDATE {$ dbtbpre} ecms_news set titlesss = 'title' where id = 1 "); var_dump ($ SQL); hr (); db_close (); $ empire = null;?>

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.

 ';}$ SQL = $ empire-> query1 ("select id, title from {$ dbtbpre} ecms_news"); var_dump ($ SQL); hr (); // if the statement is successfully executed, true $ SQL = $ empire-> query1 ("UPDATE {$ dbtbpre} ecms_news set title = 'Test UPDATE title' where id = 1 "); var_dump ($ SQL); hr (); // if the statement execution fails, FLASE $ SQL = $ empire-> query1 ("UPDATE {$ dbtbpre} ecms_news set titlesss = 'Test UPDATE title' where id = 1") is returned "); var_dump ($ SQL); hr (); db_close (); $ empire = null;?>

....

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.