O'Reilly logo

Learning PHP 5 by David Sklar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Installing PEAR

Many PEAR modules, such as the DB module discussed in Chapter 7, make your PHP programming life easier. They are high-quality code libraries that help you do all sorts of common tasks in PHP programs such as interacting with a database or generating an HTML form. I recommend always having the PEAR libraries available.

Depending on how you have installed PHP (or how your hosting provider has installed PHP), you may need to take extra steps to also install the PEAR base libraries (including DB) and its package management tool. To see whether you have PEAR installed properly, make a short PHP program that just attempts to include DB.php, as shown in Example A-2.

Example A-2. Testing for PEAR installation

require 'DB.php';
if (class_exists('DB')) {
    print "ok";
} else {
    print "failed";
}

If PEAR is installed properly, Example A-2 prints ok. PEAR is not installed correctly if the program prints failed, you get a blank page, or you see an error message like this:

Warning: main(DB.php) [function.main]: failed to open stream:
No such file or directory in /usr/local/apache/htdocs/pearcheck.php on line 2

Fatal error: main( ) [function.require]: Failed opening required 'DB.php'
(include_path='.:/usr/local/php/lib') in /usr/local/apache/htdocs/pearcheck.php
on line 2

The specific steps to take to start the PEAR installation process vary based on your operating system. On Windows, visit http://go-pear.org/ in a web browser and save the contents of that page as C:\PHP\go-pear.org (assuming ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required