PHP DevCenter

oreilly.comSafari Books Online.Conferences.

We've expanded our Linux news coverage and improved our search! Search for all things LAMP across O'Reilly!

Search
Search Tips

advertisement

Listen Print Discuss Subscribe to PHP Subscribe to Newsletters

An Introduction to PEAR
Pages: 1, 2

Installing PHP from CVS

If you have never heard of CVS, take a look at the related documentation. It is not a difficult technology to use, but it takes a while to become comfortable with it.



Assuming you already have the standard CVS client installed correctly on your machine, you will need to follow these steps:

1. Open a terminal window (rxvt, xterm, or whatever)

2. Type the following commands:

cvs -z3 -d :pserver:cvsread@cvs.php.net:/repository login
Password:
[Enter phpfi as the password here]
cvs -z3 -d :pserver:cvsread@cvs.php.net:/repository co php4
[This will create a new directory named php4]
cd php4
cvs -z3 -d :pserver:cvsread@cvs.zend.com:/repository login
Password:
[Enter zend as the password here]
cvs -z3 -d :pserver:cvsread@cvs.zend.com:/repository co Zend TSRM
[This will create two new directories under "php4", named "Zend" and "TSRM"]
./buildconf

That was it. Running buildconf should create the standard configure script that can be used to set your options for PHP. In a normal installation, PEAR should be installed automatically under /usr/local/lib/php, but you can still build the files manually by going into php4/pear and running make install-su as a superuser.

Besides that, you should add the PEAR root directory to the include_path found in your php.ini file. The default path should be /usr/local/lib/php, but it may be elsewhere if you did some manual changes to your configure options.

Starting up with PEAR

PEAR packages can range from database abstraction layers to output cache systems, so PEAR is much more than a simple library -- it is a new standard of writing portable and clean PHP code. One of the most important things for a PEAR newcomer to do is to read the coding standards that are published in the PHP manual.

I'll give some tips on how to start working with PEAR::DB, because it is one of the most popular PEAR packages. You can get examples and help on how to use PEAR::DB by following these steps:

  • Search MARC under PEAR-DEV or PEAR-GENERAL for answers to your questions.
  • Read the unit-test scripts provided with the source code of PEAR. The location of these scripts can be found in the directory where your PHP CVS source is. In my case, it was /home/jpm/php4/pear/DB/tests/.
  • Go through Tomas Cox's excellent PEAR::DB tutorial.

I hope this article has shed some light on the semi-mysterious PEAR library, and that it has provided you with some useful background information on one of the more promising developments in the PHP community.

Enjoy!

Joao Prado Maia is a web developer living in Houston with more than four years of experience developing web-based applications and loves learning new technologies and programming languages.


Return to the PHP DevCenter.


Give this a try and let us know how it compares to Perl's CPAN.
You must be logged in to the O'Reilly Network to post a talkback.
Post Comment
Full Threads Oldest First

Showing messages 1 through 7 of 7.

  • how to locate DB.php
    2007-09-21 07:34:52  callmahais [Reply | View]

    how do i rectify this error:
    Warning: require_once(DB.php) [function.require-once]: failed to open stream: No such file or directory in C:\Program Files\Apache Group\Apache2\htdocs\mahais\createtable.php on line 6

    Fatal error: require_once() [function.require]: Failed opening required 'DB.php' (include_path='.;c:\php\includes;c:\php\PEAR') in C:\Program Files\Apache Group\Apache2\htdocs\mahais\createtable.php on line 6
  • how can I tell if PEAR is installed?
    2001-08-29 08:42:13  ziatroyano [Reply | View]

    My site is hosted by another provider. Is there a way I can tell if PEAR is installed on the server without having direct access to it?
    • how can I tell if PEAR is installed?
      2007-03-18 09:15:56  ajay.kumar.singh [Reply | View]

      You should have install driver for mysql

      $dsn = 'mysql://test_user:test_pw@localhost/test_db';

      simpleQuery is not in use right now, to launch the query simply use $dbobj->query() passing a query string in query function using above dsn.

      Regards,

      ajay
    • how can I tell if PEAR is installed?
      2003-10-20 13:55:24  anonymous2 [Reply | View]

      Assuming your machine has PEAR configured correctly and all is well the following should enlighten you as to if it is installed. Note though they may not have this package (PEAR_Info) installed... so you would prob get a fatal error... if your lucky provided by PEAR...if its installed :) - by the way when i checked this there was not docs for this package when i checked it (20th Oct 2003)... these are some of the main functions inside that class... along with

      function setProxy($proxy)
      function getPackages()
      function getConfig()
      function getCredits()
      function pearImage() {
      function show() {

      <?php
      // Include the appropriate PEAR classes
      require_once("PEAR/Info.php");
      $pearinfo = &new PEAR_Info();
      $pearinfo->getPackages();
      $pearinfo->getConfig();
      $pearinfo->getCredits();
      ?>
      • how can I tell if PEAR is installed?
        2007-07-24 07:52:42  tomski [Reply | View]

        I get an error when running getPackages()

        Warning: Invalid argument supplied for foreach() in D:\xampplite\php\pear\PEAR\Info.php on line 235

        Here's the whole script for packages, Line 235 is bold.

        function getPackages()
        {
        $latest = @$this->r->call('package.listLatestReleases');
        $available = $this->reg->listPackages();
        if (PEAR::isError($available)) {
        echo '<h1 style="font-size: 12px;">An Error occured fetching the package list. Please try again.</h1>';
        return FALSE;
        }
        if (!is_array($available)) {
        echo '<h1 style="font-size: 12px;">The package list could not be fetched from the remote server. Please try again.</h1>';
        return FALSE;
        }
        natcasesort($available);
        if ((PEAR::isError($latest)) || (!is_array($latest))) {
        $latest = FALSE;
        }
        $packages = '';
        foreach ($available as $name) {
        $installed = $this->reg->packageInfo($name);
        if (strlen($installed['package']) > 1) {
        if (!isset($old_index)) {
        $old_index = '';
        }
        $current_index = $name{0};
        if (strtolower($current_index) != strtolower($old_index)) {
        $packages .= ' () ';
        $old_index = $current_index;
        $this->index[] = $current_index;
        }
        $packages .= '
        <h2>' .trim($installed['package']). ' () </h2>
        <table>
        <tr class="v">
        <td class="e">
        Summary
        </td>
        <td>
        ' .nl2br(htmlentities(trim($installed['summary']))). '
        </td>
        </tr>
        <tr class="v">
        <td class="e">
        Version
        </td>
        <td>
        ' .trim($installed['version']). '
        </td>
        </tr>
        <tr class="v">
        <td class="e">
        Description
        </td>
        <td>
        ' .nl2br(htmlentities(trim($installed['description']))). '
        </td>
        </tr>
        <tr class="v">
        <td class="e">
        State
        </td>
        <td>
        ' .trim($installed['release_state']). '
        </td>
        </tr>
        <tr class="v">
        <td class="e">
        Information
        </td>
        </tr>';
        if ($latest != FALSE) {
        if (isset($latest[$installed['package']])) {
        if (version_compare($latest[$installed['package']]['version'],$installed['version'],'>')) {
        $packages .= '<tr class="v">
        <td class="e">
        Latest Version
        </td>
        <td>
        ' .$latest[$installed['package']]['version'] . ' (http://pear.php.net/get/' .trim($installed['package']). ')
        ('. $latest[$installed['package']]['state']. ')
        </td>
        </tr>';
        }
        }
        }
        $packages .= ' <tr>
        <td colspan="2" class="v">Top (#top) </td>
        </tr>
        </table>';
        }
        }
        ?>
        <h2>PEAR Packages () </h2>
        <table style="padding: 3px;">
        <tr>
        <td class="e">
        Index
        </td>
        </tr>
        <tr>
        <td class ="v" style="text-align: center">
        <?php
        foreach ($this->index as $i) {
        ?>

        | <?php echo strtoupper($i); ?> (#<?php echo $i; ?>)
        <?php
        }
        ?>|
        </td>
        </tr>
        </table>


        <?php
        echo $packages;
        }

        <b>Thanks for for any help. I would like to view my installed packages.

        Tom

        Please send response to tturowski@gmail.com also.
      • how can I tell if PEAR is installed?
        2007-07-24 07:52:05  tomski [Reply | View]

        I get an error when running getPackages()

        Warning: Invalid argument supplied for foreach() in D:\xampplite\php\pear\PEAR\Info.php on line 235

        Here's the whole script for packages, Line 235 is bold.

        function getPackages()
        {
        $latest = @$this->r->call('package.listLatestReleases');
        $available = $this->reg->listPackages();
        if (PEAR::isError($available)) {
        echo '<h1 style="font-size: 12px;">An Error occured fetching the package list. Please try again.</h1>';
        return FALSE;
        }
        if (!is_array($available)) {
        echo '<h1 style="font-size: 12px;">The package list could not be fetched from the remote server. Please try again.</h1>';
        return FALSE;
        }
        natcasesort($available);
        if ((PEAR::isError($latest)) || (!is_array($latest))) {
        $latest = FALSE;
        }
        $packages = '';
        foreach ($available as $name) {
        $installed = $this->reg->packageInfo($name);
        if (strlen($installed['package']) > 1) {
        if (!isset($old_index)) {
        $old_index = '';
        }
        $current_index = $name{0};
        if (strtolower($current_index) != strtolower($old_index)) {
        $packages .= ' () ';
        $old_index = $current_index;
        $this->index[] = $current_index;
        }
        $packages .= '
        <h2>' .trim($installed['package']). ' () </h2>
        <table>
        <tr class="v">
        <td class="e">
        Summary
        </td>
        <td>
        ' .nl2br(htmlentities(trim($installed['summary']))). '
        </td>
        </tr>
        <tr class="v">
        <td class="e">
        Version
        </td>
        <td>
        ' .trim($installed['version']). '
        </td>
        </tr>
        <tr class="v">
        <td class="e">
        Description
        </td>
        <td>
        ' .nl2br(htmlentities(trim($installed['description']))). '
        </td>
        </tr>
        <tr class="v">
        <td class="e">
        State
        </td>
        <td>
        ' .trim($installed['release_state']). '
        </td>
        </tr>
        <tr class="v">
        <td class="e">
        Information
        </td>
        </tr>';
        if ($latest != FALSE) {
        if (isset($latest[$installed['package']])) {
        if (version_compare($latest[$installed['package']]['version'],$installed['version'],'>')) {
        $packages .= '<tr class="v">
        <td class="e">
        Latest Version
        </td>
        <td>
        ' .$latest[$installed['package']]['version'] . ' (http://pear.php.net/get/' .trim($installed['package']). ')
        ('. $latest[$installed['package']]['state']. ')
        </td>
        </tr>';
        }
        }
        }
        $packages .= ' <tr>
        <td colspan="2" class="v">Top (#top) </td>
        </tr>
        </table>';
        }
        }
        ?>
        <h2>PEAR Packages () </h2>
        <table style="padding: 3px;">
        <tr>
        <td class="e">
        Index
        </td>
        </tr>
        <tr>
        <td class ="v" style="text-align: center">
        <?php
        foreach ($this->index as $i) {
        ?>

        | <?php echo strtoupper($i); ?> (#<?php echo $i; ?>)
        <?php
        }
        ?>|
        </td>
        </tr>
        </table>


        <?php
        echo $packages;
        }

        <b>Thanks for for any help. I would like to view my installed packages.

        Tom
  • A little correction in the example
    2001-06-23 04:01:09  tvvcox [Reply | View]

    Hi Joao,

    Very nice to see that article here in Onlamp and thanks also for the good critic on my Pear DB Tut. Just only few corrections in the example you give:

    1) $dsn = array(
    'phptype' => 'mysql',
    'hostspec' => 'localhost',
    'database' => 'test_db',
    'username' => 'test_user',
    'password' => 'test_password'
    );

    This is supported, but the "string" format is shortest and more recomended. So:
    $dsn = 'mysql://test_user:test_pw@localhost/test_db';

    2) simpleQuery is not in use right now, to launch the query simply use $dbh->query().

    Regards,

    Tomas V.V.Cox


Tagged Articles

Post to del.icio.us

This article has been tagged:

pear

Articles that share the tag pear:

The Dynamic Duo of PEAR::DB and Smarty (37 tags)

Programming eBay Web Services with PHP 5 and Services_Ebay (12 tags)

Three-Tier Development with PHP 5 (6 tags)

PHP's PEAR on Mac OS X (6 tags)

Caching PHP Programs with PEAR (6 tags)

View All

php

Articles that share the tag php:

Understanding MVC in PHP (477 tags)

The PHP Scalability Myth (123 tags)

The Dynamic Duo of PEAR::DB and Smarty (53 tags)

PHP Form Handling (43 tags)

Very Dynamic Web Interfaces (39 tags)

View All

Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
O'Reilly FYI
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com