Smarty Example Tutorial IV: Example (using the DB Class of Phplib)

Source: Internet
Author: User
Tags root directory

A few days ago some things, so this example to write until today, why take the phplib in the DB class? Many people in the study of PHP, may be the first contact with the template is Phplib, the reason is very simple: a lot of PHP learning materials are introduced phplib,phplib in PHP3 when the fire, one of the reasons is that it achieved in PHP3 did not implement the session function, Until now there are still a lot of people using phplib template technology, because it is very simple. At the same time, the database operation class on the phplib is very popular because of its small file and fast loading speed. I like the syntax of it and feel very close to the MySQL statement in PHP. OK, no more nonsense, come to see our program. The program also takes instance one the site to say, regarding the database establishment and the template establishment here does not say, please take a look at the section the introduction, here mainly introduces the new addition in the procedure the thing. First look at the table of contents:

+web (site root directory)

|
|----+COMM (smarty Related documents directory)
| |
| |----+plugins (smarty plugin directory)
| |-----Config_File.class.php (SMA Rty configuration file
| | |-----Smarty.class.php (Smarty class Master)
| |-----Smarty_Compiler.class.php (Smarty compile class file)
| |-----db_ mysql.inc.php (DB Class in Phplib)
| | |-----csub.inc.php (a function to intercept Chinese)
|
|----+cache (smarty cache directory, *nix guaranteed read and Write permissions)
|
|----+templates (site template file storage directory)
| |
| |----HEADER.TPL (page header template file)
| | |----INDEX.TPL (site template file)
| |----FOOT.TPL (page footer template file)
| |----NEWS.TPL (News page template file)
|
|
|----+templates_c (template file is compiled and stored in directory, *nix guaranteed read and Write permissions)
|
|----+CSS ( Site css file directory
|
|----+image (site Picture catalog)
|
|----+media (SITE Flash animation storage directory)
|
|----indexbak.htm (Original effect map of homepage) br> |
|----newsbak,htm (News page Original effect chart)
|
|----index.php (smarty First program file)
|
|----news.php (SMARTY News display file)
|
|----Routines description. txt (this document)

Here is mainly in the/comm/directory more than two files, one is db_mysql.inc.php, in phplib its file name db_mysql.inc,inc file in the browser by default when directly positioned from the browser will be displayed in browsers, so for security we will Its extension is changed to db_mysql.inc.php; The second file is a function that contains the characters in the Intercept

Csubstr (), when used, we will display its source code.

Here we will give you a brief introduction to the main member variables and member functions of the Db_sql defined in db_mysql.inc.php:

One, the member variable:

1. $Host: Host Name

2. $Database: Database name

3. $User: User Name

4. $Password: Password

Second, the member function:

1. Connect ($Database = "", $Host = "", $User = "", $Password = ""): Establish a connection, return the connection ID

2. Query ($Query _string): Queries, returns the query ID

3. Free (): Frees the current Query ID resource

4. Next_record (): Returns the next return set

5. Num_rows (): Number of data rows in the current query number

6. F ($name): The value of the current field

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.