Hudzilla.org - the homepage of Paul Hudson
Contents > Introducing PHP Wish List | Report Bug | About Me ]

2.4     PEAR

This is NOT the latest copy of this book; click here for the latest version.

The PHP Extension and Application Repository, or PEAR for short contains code written by other programmers to achieve various goals. The concept is simple: other programmers, usually specialists in their areas, write very complicated code, and present it to you in an easy-to-use form, thereby enabling you to create very powerful scripts using just a few simple commands.

PEAR contains two types of pre-written code: PECL code, and PHP code. PECL code, as mentioned already, forms full extensions written in C that interact with external libraries. Extensions reside in PECL when they are considered useful, but not popular or much used. Most of PEAR, however, is PHP code that performs all varieties of tasks for you, with the primary advantage being that you can use PEAR code on any PHP server without needing to enable any extensions or re-compile PHP.

The most famous package in PEAR is called PEAR::DB, and provides an object-oriented, database-independent framework for reading and writing to your database. PEAR::DB is covered in depth later on.

PHP comes with "go-pear", an easy way to configure PEAR for use on your computer. To use it, simply run go-pear from the command line and follow the on-screen instructions. Windows users will need to change directory to where PHP is, e.g. c:\php.



Once you have PEAR installed on yor system, you will see the "pear" command - this allows you to search for and download new PEAR modules for your PHP installation.

Author's Note: I've had people email me asking why my code examples rarely make use of PEAR - sometimes I write things from scratch rather than using the pre-built PEAR code. Well, there are two reasons for this: first, if I teach you how to use PEAR, you won't learn how to do it yourself. This is not necessarily a bad thing; certainly I wouldn't want to try re-implementing parts of C++'s Standard Template Library! However I think there's a lot to be learnt by writing things yourself. The second - and important - reason is that PEAR isn't installed on that many web servers, or if it is installed it may not be kept up to date. So if I had used PEAR in my code examples, many thousands of you wouldn't be able to use them because your host provider doesn't support it! That, in a nutshell, is why I haven't used PEAR very much - sorry!





<< 2.3 Extending PHP   2.5 Running PHP scripts >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
A PHP User - 13 Oct 2008

it is avery go opportunity for one to get this book and read cos you wil gain more in php and javascript programming, i really appreciate it and thanks for the creating this book for us beginners'.

hebrego - 13 Oct 2008

I think in this part of the course could be mentioned how to install php in the computer and what program use to install it easyly.

Smartdog - 13 Oct 2008

It would be nice if the screen shot used a greater height and width or was a link to a bigger sized image.

Great read so far...already have the new book (good for you!!..nice job)

msszroberts@yahoo.com - 13 Oct 2008

Just a small typo on page 2-4.

You wrote:
Once you have PEAR installed on yor system, you will see the "pear" command

I believe you wanted to write:
on your system.

Thanks

A PHP Beginner - 13 Oct 2008

This is an outstanding tutorial. I've already decided to buy the book.

I find this to be very encouraging:

"I think there's a lot to be learnt by writing things yourself."

Which has been my exact approach in learning JavaScript. I don't want to simply learn the language, I want to speak it.

For what it's worth, with JavaScript I started out with David Thau's book. Subsequent to that I read David Flanagan's book, who I believe is a colleague of yours at O'reilly.

Wanna Use Pear - 13 Oct 2008

This section should go into a bit more detail.

- How can I tell if my host has pear installed.
- How do I add more pear modules
- How do I call pear modules.

cronayne@lycos.co.uk - 13 Oct 2008

http://www.ricocheting.com/server/

Will sort out those problems for you. And instead of doing a blind MSI install, or unzipping to certain directories, you get to find out how and why you are doing what you are doing.

cronayne@lycos.co.uk - 13 Oct 2008

http://www.ricocheting.com/server/

Will sort out those problems for you. And instead of doing a blind MSI install, or unzipping to certain directories, you get to find out how and why you are doing what you are doing.

A PHP User - 13 Oct 2008

Go to www.sourceforge.net. Search for apache + php (both words) You will find tons of free installers that will setup php, apache, mysql etc for you. This is a good start for development because it saves you from configuration hassel and you can start development right away.
my favourite: vertigo (also at sourceforge)

Maryam

A PHP User - 13 Oct 2008

Go to www.sourceforge.net. Search for apache + php (both words) You will find tons of free installers that will setup php, apache, mysql etc for you. This is a good start for development because it saves you from configuration hassel and you can start development right away.
my favourite: vertigo (also at sourceforge)

Maryam

A PHP Newbie - 13 Oct 2008

Why is PHP so hard to install? Why isn't there a universal installer for each version released? The stupid crap of a dumb installer/whatever it is didn't do much. I still can't run PHP. I'd probably give up if I wasn't going to make money off actually learning this frustrating crap.

A PHP Newbie - 13 Oct 2008

...It says bad command or file name.

A PHP Newbie - 13 Oct 2008

When I go to my command prompt and browse to my PHP directory (C:\PHP\) and type in go-pear, it does not run.

I saved go-pear.php from the website you provided.



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is seven plus ten?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow