Use PHPLIB to visit multiple databases

Source: Internet
Author: User
PHPLIB is an extended PHP library. we can easily control the database by using it. However, if you want to apply multiple databases, it will not be enough, this article first introduces how to expand PHPLIB so that you can have both the fish and the bear's paw,

PHPLIB is an extended PHP library. we can easily control the database by using it. However, if you want to apply multiple databases, it will not be enough, this article first introduces how to expand PHPLIB so that you can have both the fish and the bear's paw. you can apply multiple databases while applying PHPLIB, in addition, you can also learn about object-oriented programming and how to expand the library, which is worth reading.

Database governance

You can put any table in a large database. However, after a long period of time, the database will become larger and larger, and the server may not be able to keep up with the I/O work, or there is not enough memory for all visits? It is very difficult to leave the existing data. The wise measure is to apply the database that leaves at the beginning and conduct effective database governance. If you have a website for selling books, you may have a list of authors, a list of book prices, and a list of current inventory and orders. As your business continues to increase, orders will continue to increase, and a lot of disk visits are required to process each order. It is very likely that you will put all the orders in an accounting system one day.

Now, place the order in an independent database. Because the inventory is updated through the order, the inventory is also placed in the same database.

The author's list and book list are static information that must be read frequently but rarely updated. In fact, updating an author's record may only take 5 years, only when the author writes a new book (or dies. The configuration of the server where the data is stored can be different from that of the server where the order database is placed.

Including PHPLIB

PHPLIB uses a class called DB_ SQL to visit the SQL database. Include different inc files in your code based on the database type you need to apply. In this example, I applied the MySQL version.

To apply DB_ SQL in your code, install the PHPLIB files in their own directories. Then, find your cgi-bin directory and create the phplib directory next to the cgi-bin directory. Next, copy all PHPLIB. inc files to the phplib directory. Finally, modify the php. inc file and change the "export de_path =" line to the phplib directory.

Include_path is the directory found when the PHP application include () or require (). in my NT workstation, the include path is:

Include_path = '.; I:/project52/shortdes; I:/project52/phplib ';

On a Linux system

Include_path = '.;/home/httpd/shortdes;/home/httpd/phplib ';

At the top of each PHP page
<? Php

Require (common. php );

?>
Common. php3 is placed in the "des" directory, which contains all the data and functions required for each page. In this example, common. php is:
<? Php

Require (db_mysql.inc );
Require (ct_ SQL .inc );
Require (session. inc );
Require (auth. inc );
Require (perm. inc );
Require (user. inc );
Require (page. inc );

?>

If you want to know the usefulness of each inc file, you can browse the PHPLIB documentation on the http://phplib.netuse.de. Db_mysql.inc contains the definitions of all DB_ SQL classes. If you want to use PostGreSQL instead of MySQL, you only need to use db_pgsql.inc instead of db_mysql.inc. There are 10 other. inc files that can be applied to ms SQL, Oracle, Sybase, or other databases.

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.