Uchome: Database Class class_mysql.php

Source: Internet
Author: User
Tags pconnect

Uchome implements an encapsulation class for MySQL databases without using open-source database frameworks such as ADODB or pear. The advantage of doing so is that there are very few files and the space is very small.

1. Database Configuration
Like many PHP projects, the uchome database configuration is placed in the config. PHP configuration file, from row 9th to line 16:

 $ _ SC ['Dbhost'] = 'localhost '; //  Du ????  $ _ SC ['Dbuser'] = 'root' ;  $ _ SC ['Dbpw '] ='' ;  $ _ SC ['Dbcharset'] = 'utf8' ;  $ _ SC ['Pconnect '] = 0;  $ _ SC ['Dbname'] = 'comsenz' ;  $ _ SC ['Tablepre'] = 'uchome _' ;  $ _ SC ['Charset'] = 'utf-8'; the content of config. php is installed Program Write, which is introduced by common. php after writing, and the imported content is stored in global variables. $ _ SC .

 

2. Database Connection
In the 42nd line of common. php, there is a function call:
Dbconnect ();The function dbconnect () is used to execute database connection processing. It is defined in rows 108th to 118 of function_common.php (this file is introduced by common. php:

 Function Dbconnect (){  Global   $ _ Sglobal , $ _ SC  ;  Include_once (S_root. './source/class_mysql.php' );  If ( Empty ( $ _ Sglobal ['Db' ]) {  $ _ Sglobal ['Db'] = New  Dbstuff; $ _ Sglobal ['Db']-> charset = $ _ SC ['Dbcharset' ];  $ _ Sglobal ['Db']-> connect ( $ _ SC ['Dbhost'], $ _ SC ['Dbuser'], $ _ SC ['Dbpw '], $ _ SC ['Dbname'], $ _ SC ['Pconnect' ]) ;}} 

 

Source/class_mysql.php is the MySQL encapsulation class of uchome. From the above function definition, we can see that the MySQL encapsulation class name is dbstuff, And the dbconnect () function creates an instance of this class, then set the character encoding and execute the connection. The class instance is placed in $ _ sglobal ['db'].

3. indicates the prefix.
Many PHP projects can be configured to indicate the prefix. In this way, you can install the same program multiple times in a database, or uchome. Uchome indicates that the prefix is configured through $ _ SC ['tablepre']. The default value is uchome _. During SQL query, the prefix is added by calling the tname () function.
The tname () function is defined in rows 216th to 219 of function_common.php:

 
FunctionTname ($ Name){Global $ _ SC;Return $ _ SC['Tablepre'].$ Name;}

 

Usage:

 
$ Query=$ _ Sglobal['Db']-> query ("select * from". tname ('magicinlog ');

 

4. Database Query
An example of a database query:

 
$ Query=$ _ Sglobal['Db']-> query ("select * from". tname ('magicinlog');While($ Value=$ _ Sglobal['Db']-> fetch_array ($ Query)){$ List[] =$ Value;}

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.