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:
- Create a test directory under the e directory, for example, e/trylife/td-test/
- Create a PHP file under the directory in 1, for example, I created e/trylife/td/test-db_ SQL .php
- 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
- Query () executes mysql_query ()
- 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.
- 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 '