Installing PEAR - Including a Package Within Your Scripts
(Page 3 of 4 )
Using an installed PEAR package is simple. All you need to do is make the package contents available to your script with include or preferably require. Keep in mind that you need to add the PEAR base directory to yourinclude_pathdirective; otherwise, an error similar to the following will occur:
-------------------------------------------- Fatal error: Class 'MDB2' not found in /home/www/htdocs/book/11/database.php on line 3 --------------------------------------------
Those of you with particularly keen eyes might have noticed that in the earlier example involving theNumbers_Romanpackage, a directory was also referenced:
require_once("Numbers/Roman.php");
A directory is referenced because theNumbers_Romanpackage falls under theNumberscategory, meaning that, for purposes of organization, a corresponding hierarchy will be created, withRoman.phpplaced in a directory namedNumbers. You can determine the package’s location in the hierarchy simply by looking at the package name. Each underscore is indicative of another level in the hierarchy, so in the case ofNumbers_Roman, it’sNumbers/Roman.php. In the case ofMDB2, it’s justMDB2.php.
Note See Chapter 2 for more information about theinclude_pathdirective.
See Chapter 2 for more information about the directive.
Upgrading Packages
All PEAR packages must be actively maintained, and most are in a regular state of development. That said, to take advantage of the latest enhancements and bug fixes, you should regularly check whether a new package version is available. You can upgrade a specific package, or all packages at once.
Upgrading a Single Package
The general syntax for upgrading a single package looks like this:
%>pear upgrade [package name]
For instance, on occasion you’ll want to upgrade the PEAR package, responsible for managing your package environment. This is accomplished with the following command:
%>pear upgrade pear
If your version of a package corresponds with the latest release, you’ll see a message that looks like the following:
If for some reason you have a version that’s greater than the version found in the PEAR repository (e.g., you manually downloaded a package from the package author’s Web site before it was officially updated in PEAR), you’ll see a message that looks like this:
-------------------------------------------- Package 'PEAR' version '1.4.9' is installed and 1.4.9 is > requested '1.4.8', skipping --------------------------------------------
Otherwise, the upgrade should automatically proceed. When completed, you’ll see a message that looks like the following:
It stands to reason that you’ll want to upgrade all packages residing on your server, so why not perform this task in a single step? This is easily accomplished with theupgrade-allcommand, executed like this:
%>pear upgrade-all
Although unlikely, it’s possible some future package version could be incompatible with previous releases. That said, using this command isn’t recommended unless you’re well aware of the consequences surrounding the upgrade of each package.