To create a tool similar to the Perl cpan file, Stig S. Bakken created the Pear project. The basic goal of pear is to develop a knowledge base for PHP extensions and library code, and the most ambitious goal of the project is to try to define a standard that will help developers write portable, reusable code.
There are already some documents on the project on the Internet. For example, some of the initial data can be found in the PHP official manual and more information will be added.
To a large extent, pear is still a work in progress. In the next few months, the pear installer and the Pear Web site will be greatly developed. There has been a lot of discussion on the PHP Core developer mailing list to use the growing C extension of pear in the next version of PHP, and the use of the Pear installer as a user to download and install extensions to PHP's front-end tools.
In addition, we must also focus on Pear's PHP library code. Pear's PHP library code is often considered to be the best and most uncluttered library in the current design. PEAR::D B is one of the most popular packages, which is a database abstraction library created by the Pear project. Bakken is trying to migrate its main classes and functions onto C extensions, making the package the best performance.
There is no doubt that this new project will become one of the most important components of PHP in the future, making it easy for developers to share code through the Pear Web site, allowing users to easily download and install extensions, PHP code libraries.
Second, how to use pear?
As mentioned earlier, pear is constantly developing and improving. However, there are already a lot of packages available to use now. One of the most popular packages is pear::D B, which enables developers to write code that can be used at the same time for a variety of different database servers. For example, a developer can write a script that inserts a database record into a table, and this script applies to MySQL, PostgreSQL, and Oracle.
In other words, the following example can be applied to all different types of database servers:
<?php
Introducing the Right Pear class
Require_once ("db.php");
$stmt = "SELECT ID, name from examples order by id";
$result = $dbh->simplequery ($stmt, DB_FETCHMODE_ASSOC);
if ($dbh->numrows ($result) > 0) {
$data = (object) $dbh->fetchrow ($result, DB_FETCHMODE_ASSOC);
echo "id => $data->id<br>\n";
echo "Name => $data->name<br>\n";
}
?>
This is a simple example of what it is like to use abstract library programming like pear::D B.
Recently, a new chapter in the PHP Basic Handbook has been added. However, it is not clear whether the manual contains a description of the entire Pear library, or a separate manual for each pear package.
Third, installation
Installing pear is actually very simple. Since the Pear library is updated quickly, here's how to install the latest CVS version of Pear.
Note: The pear internal Knowledge Base system may change in the future. For now, pear packages, libraries, and PHP itself are saved to the same CVS tree, which can lead to problems in managing the PHP Master Knowledge Base and developers, and the knowledge base and developers of pear itself. It can be expected that in the near future, pear will be separated into separate modules/trees. This module already exists, but most of the packages are still in the old position.
If you have never heard of CVS, please look at the relevant information. CVS is not a particularly difficult technology, but it takes a certain amount of time to be familiar with it.
Suppose you have a standard CVS client software installed on your machine, and then you should:
Open a terminal window (Rxvt,xterm, or other).
Enter the following command:
cvs-z3-d:p server:cvsread@cvs.php.net:/repository Login
Password: [Enter "PHPFI" as password here]
cvs-z3-d:p Server:cvsread@cvs.php.net:/repository Co PHP4
[This command will create a new directory PHP4]
CD PHP4
cvs-z3-d:p server:cvsread@cvs.zend.com:/repository Login
Password: [Enter password here Zend]
cvs-z3-d:p server:cvsread@cvs.zend.com:/repository Co zend TSRM
[This command will create two new directories under PhP4, named "Zend" and "TSRM"]
./buildcon
This is the entire installation process. Running buildconf will create a standard configure script that can be used to set PHP options. In the default installation, pear is automatically installed under/usr/local/lib/php. However, you can also manually construct individual files by entering as Superuser, go to the Php4/pear directory, and execute make INSTALL-SU.
In addition, you should add the Pear root directory to the include_path of the php.ini file. The default directory should be/usr/local/lib/php, but if you manually modify the option, it may be in another location.
Iv. Getting Help
Pear's package covers everything from the database abstraction layer to the output buffering system, so pear is far more than a simple library--it's a new standard for writing neat, portable code. One of the most important things for a pear novice is to read the coding standards published in the PHP manual. Here are a few places to get help information for pear:
Look for Pear-dev or pear-general to find the answer to the question.
Check the unit test script that accompanies the Pear source code. These scripts are located under the directory where the PHP CVS source code resides. For example, here in my case, it is/home/jpm/php4/pear/db/tests/.
Read through Tomas Cox's excellent pear::D B Guide.
So far, the true colors of pear have not been fully revealed to the world. However, I hope that this article has succeeded in outlining its general appearance for you.
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.