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;}