Go Back   SitePoint Forums > Forum Index > Program Your Site > PHP > PHP Application Design
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Dec 4, 2003, 20:58   #1
mwmitchell
SitePoint Guru
 
Join Date: May 2003
Location: virginia
Posts: 991
Advice on a 'bigger' site. PEAR opinions?

I'm re-building a website that is pretty large in that it has members, member "storefronts" all kinds of categories that change dynamically, an admin front-end, etc...

The site is built from PEAR:B and Smarty now. I didn't want to re-build it using PEAR, or Smarty but...

I started messing around with PEAR DB_DataObject tonight and I'm blown away at how easy it is to access "entities" now. It's so easy that it doesn't matter to me if the PEAR code is what some people call "bloated". This is going to make my life so much easier.

I'm wondering if anyone has any experience with any of the following classes:

DB
DB_DataObject
HTML_QuickForm
HTTP_Upload
DB_Pager
Mail

Pros/Cons? I know there are a lot of tutorials out there, but I want some real feedback.

I've actually always been oppossed to using large, open-source libraries (because it's so much more fun for me to code), but if these packages are *stable*, that's all that matters.

Thanks!

Matt
mwmitchell is offline   Reply With Quote
Old Dec 5, 2003, 00:56   #2
astericks
My precious!!!
 
astericks's Avatar
 
Join Date: Mar 2002
Location: Vancouver, BC
Posts: 2,021
I just thought I'd toss in another question:

Does the pearDB package have any edge of the eclipse package by Vincent?
astericks is offline   Reply With Quote
Old Dec 5, 2003, 01:04   #3
Phil.Roberts
No.
 
Phil.Roberts's Avatar
 
Join Date: May 2001
Location: Nottingham, UK
Posts: 1,147
Quote:
Originally Posted by astericks
I just thought I'd toss in another question:

Does the pearDB package have any edge of the eclipse package by Vincent?
Only in terms of extended functionality.... But simplicity goes straight out the window.
Phil.Roberts is offline   Reply With Quote
Old Dec 5, 2003, 04:11   #4
prefab
SitePoint Zealot
 
prefab's Avatar
 
Join Date: Jan 2003
Location: Belgium
Posts: 133
Quote:
Originally Posted by mwmitchell
I'm wondering if anyone has any experience with any of the following classes:

DB
DB_DataObject
HTML_QuickForm
HTTP_Upload
DB_Pager
Mail
Hi,

I see you found your way to DB_DataObject too that package alone made me consider PEAR too.
Now I'm working on my own PEAR based framework (actually, the framework itself is based on Ismo,
ismo.sf.net, while most of the added functionality stems from PEAR based work).

I even got involved in a couple of projects myself. If you like DB_DataObject, I can recommend DB_DataObject_Formbuilder which can create QuickForm forms form your DBDO.
You can customize the form in any way you like. So I would recommend QuickForm too.

To me the talks about the PEAR bloat seem to originate from complete ignorence. Plus, even if they were really,
bloated (they're not!!), the added value and convenience that help to create apps faster, far outweights that.
Besides, servers get faster everyday, so it's easy to compensate if needed. Hardware is cheaper
than development time IMHO.

Why is it that PEAR always gets so much bad press on these boards? There are lots of efficient and usefull packages in PEAR, good quality stuff really. Most of the packages submitted nowadays are worth their salt IMHO.

- prefab
prefab is offline   Reply With Quote
Old Dec 5, 2003, 08:31   #5
lastcraft
SitePoint Victim
 
lastcraft's Avatar
 
Join Date: Apr 2003
Location: London
Posts: 2,265
Hi...

Quote:
Originally Posted by prefab
I see you found your way to DB_DataObject too that package alone made me consider PEAR too.
It is a really easy class to implement yourself, so you are not tied to PEAR.

Quote:
Originally Posted by prefab
Why is it that PEAR always gets so much bad press on these boards?
I have personally had so much grief at various times I have almost given up on it. The error handling mechanism sucks and I have run into far too many bugs and out of date documentation. The library is also very difficult to extend, because of the large monolithic classes and lack of tests. I have to weigh evaluating using a library against writing things myself. On that basis PEAR stuff seems to take longer. Now this is a personal opinion and I could have been unlucky. The biggest disasters I have had (some time ago now, so issues may have been fixed) have been with SOAP and DB_DataObject .

I guess it depends on whether you have been burned.

yours, Marcus
lastcraft is offline   Reply With Quote
Old Dec 5, 2003, 10:20   #6
mwmitchell
SitePoint Guru
 
Join Date: May 2003
Location: virginia
Posts: 991
Quote:
Originally Posted by prefab
I even got involved in a couple of projects myself. If you like DB_DataObject, I can recommend DB_DataObject_Formbuilder which can create QuickForm forms form your DBDO.
You can customize the form in any way you like. So I would recommend QuickForm too.
Yes, i heard about DB_DataObject_Formbuilder and would like to check it out! Some times it's just nice when you can get the job finished fast, and th'at why these tools are sounding so good to me right now.


Quote:
Originally Posted by lastcraft
Hi...
It is a really easy class to implement yourself, so you are not tied to PEAR.
Marcus,

How do you mean implement myself? You mean seperate the package from the PEAR library, or write my own DataObject class/library? If you are talking about my own, could you maybe give me a few tips in the right direction? I've been using the MyDatabase from Eclipse for a long time, and haven't had any problems.

Anyone want to write out an example of a DAO/DataObject class using Eclipse Database? - would just love to see it! I have tried, and could post some examples of what I've done.

Thanks for all of the feedback!

Matt
mwmitchell is offline   Reply With Quote
Old Dec 5, 2003, 11:11   #7
lastcraft
SitePoint Victim
 
lastcraft's Avatar
 
Join Date: Apr 2003
Location: London
Posts: 2,265
Hi...

Quote:
Originally Posted by mwmitchell
Marcus,

How do you mean implement myself?
I am nowhere near my home machine right now. When I get back in a couple of days I'll post some code. It was actually the first class I ever wrote in PHP, so I'll probably cheat and tidy it up as well .

yours, Marcus
lastcraft is offline   Reply With Quote
Old Dec 5, 2003, 11:18   #8
mwmitchell
SitePoint Guru
 
Join Date: May 2003
Location: virginia
Posts: 991
Quote:
Originally Posted by lastcraft
Hi...



I am nowhere near my home machine right now. When I get back in a couple of days I'll post some code. It was actually the first class I ever wrote in PHP, so I'll probably cheat and tidy it up as well .

yours, Marcus
Allright! I look forward to your post, and thanks again!

Matt
mwmitchell is offline   Reply With Quote
Old Dec 5, 2003, 11:39   #9
sweatje
eschew sesquipedalians
 
sweatje's Avatar
 
Join Date: Jun 2003
Location: Iowa, USA
Posts: 3,764
Off Topic:

Quote:
Originally Posted by lastcraft
...
It was actually the first class I ever wrote in PHP, so I'll probably cheat and tidy it up as well .
Perhaps that would be an interesting thread: My first PHP class ( From the grizzled OO verterans at least )
sweatje is offline   Reply With Quote
Old Dec 16, 2003, 18:13   #10
mwmitchell
SitePoint Guru
 
Join Date: May 2003
Location: virginia
Posts: 991
Quote:
Originally Posted by lastcraft
Hi...
I am nowhere near my home machine right now. When I get back in a couple of days I'll post some code. It was actually the first class I ever wrote in PHP, so I'll probably cheat and tidy it up as well .

yours, Marcus
Marcus,

Are you still open to posting some code? I know you're probably busy, just thought I'd let you know that I'm still very interested!

Thanks,

Matt
mwmitchell is offline   Reply With Quote
Old Dec 5, 2003, 11:38   #11
Phil.Roberts
No.
 
Phil.Roberts's Avatar
 
Join Date: May 2001
Location: Nottingham, UK
Posts: 1,147
Quote:
Originally Posted by mwmitchell
Anyone want to write out an example of a DAO/DataObject class using Eclipse Database? - would just love to see it! I have tried, and could post some examples of what I've done.
This is probably how I would do it:

PHP Code:

<?php


include_once(APP_ROOT . 'eclipse/MyDatabase.php');

class
DAO {
    var
$dbConn;
    function
DAO() {
        
$this->dbConnect();    
    }
    
    function
dbConnect() {
        
$this->dbConn =& new MyDatabase('news_db', 'localhost');
        if(!
$this->dbConn->connect('username', 'password')) {
            
trigger_error('Unable to establish database connection.<br />
                           Error returned from MySQL: '
. $this->dbConn->getErrorMessage());
        }
    }
}

class
NewsDAO extends DAO {
    function
NewsDAO() {
        
parent::DAO();
    }
    
    function &
getAllHeadlines($offset = 0, $limit) {
        include_once(
APP_ROOT . 'eclipse/PagedQuery.php');
        
$query =& new PagedQuery(
            
$this->dbConn->query('SELECT * FROM news ORDER BY article_id DESC'), $limit
        
);
        if(!
$query->isSuccess()) {
            
trigger_error('Error while retrieving headlines.<br />$
                           Error message returned from MySQL: '
. $query->getErrorMessage())
        }

        include_once(
APP_ROOT . 'eclipse/QueryIterator.php');
        
$page = $query->getPage($offset);
        return new
QueryIterator($page);
    }
    
    function
getArticleById($id) {
        
$query =& $this->dbConn->query('SELECT * FROM news WHERE article_id=' . $id);
        if(!
$query->isSuccess()) {
            
trigger_error('Error while retrieving article.<br />
                           Error message returned from MySQL: '
. $query->getErrorMessage());
        }
        return
$query->getRow(0);
    }
}


?>
Phil.Roberts is offline   Reply With Quote
Old Dec 16, 2003, 15:19   #12
YCrowley
SitePoint Member
 
Join Date: Jan 2002
Location: My Chair
Posts: 22
Quote:
Originally Posted by Phil.Roberts
This is probably how I would do it:
A little late with a reply here, and probably an idiotic question (only just getting into OOP), how would you echo onto you page for example, $query->getRow(0);

?

ta in advance
YCrowley is offline   Reply With Quote
Old Dec 5, 2003, 08:40   #13
ghurtado
SitePoint Guru
 
ghurtado's Avatar
 
Join Date: Sep 2003
Location: Wixom, Michigan
Posts: 619
I have to agree with Marcus that one of the biggest problems PEAR has is error handling. AFAIK, its implemented by methods returning an "error object" as oppossed to "False" when they fail. Given that PHP provides you with very customizable error handling hooks, this is not only unnecesary, but completely contrary to many coding guidelines I have heard over the years. As much as I can, I always try to return false from a method that fails or throws an error.
ghurtado is offline   Reply With Quote
Old Dec 17, 2003, 09:53   #14
Taoism
SitePoint Addict
 
Join Date: Aug 2002
Location: Winnipeg, Manitoba, Canada
Posts: 214
Quote:
Originally Posted by ghurtado
AFAIK, its implemented by methods returning an "error object" as oppossed to "False" when they fail. Given that PHP provides you with very customizable error handling hooks, this is not only unnecesary, but completely contrary to many coding guidelines I have heard over the years. As much as I can, I always try to return false from a method that fails or throws an error.
Late to the thread, but I disagree with you on this. We use an error object to return errors in our code because it guarantees that the result is an error. You can say, "return a false for errors" until you run into a situation where a false is a valid result, and then you begin to code by exception.

"False means error except in this case where null means error". What happens when both null and false are acceptable? Then -1 means error? Etc...

An error object prevents this... if an error object is returned, there is no doubt that an error is the result.

Just my belated $0.02!

Cheers,
Keith.
Taoism is offline   Reply With Quote
Old Dec 17, 2003, 07:38   #15
been
SitePoint Addict
 
been's Avatar
 
Join Date: May 2002
Location: Gent, Belgium
Posts: 283
Quote:
What the hell for? It's a method that returns a single news article. Why would I need it to return any objects at all? I do that with the getAllHeadlines() method, which returns an iterator object.
I think the main reason for returning an article object would be abstraction of the column names in the database.
Suppose you wrote a nice db-abstraction layer, implemented DAO's, etc... and all of a sudden, the column names of the articles' db table get changed for whatever reason, then you'd still have to change code in the 'other layer' because the column names are reflected in the keys of the array...
been is offline   Reply With Quote
Old Dec 17, 2003, 13:39   #16
ghurtado
SitePoint Guru
 
ghurtado's Avatar
 
Join Date: Sep 2003
Location: Wixom, Michigan
Posts: 619
Perhaps throwable exceptions in PHP 5 will solve both your concerns about how to define an error and mine about mantaining error handler independance?
ghurtado is offline   Reply With Quote
Old Dec 17, 2003, 15:07   #17
HarryF
SitePoint Wizard
 
Join Date: Nov 2000
Location: Switzerland
Posts: 2,906
Late as well - on those packages;

DB - is very solid. The code could be better optimized but it does what it says on the label - DB gets heavy use and is great when you want to "step into" a database you don't know so well.

DB_DataObject - like some of the principles. The generated code you probably need to subclass with your own class so you have "fixed api" for the rest of your app. It may be I was using it wrong but I found handling table relationships cumbersome via the DB_DataObject API but otherwise it's useful to shortcut the time spent on writing (testing) hand coded SQL. Code seems a little monolithic last time I looked - lot of code in one file - might benefit from breaking it up.

HTML_QuickForm - great for a quick solution (e.g. a single page that needs a solid form) - very powerful in fact and does alot to keep you secure. Last time I tried passing an instance of quickform to another object though, things went badly wrong - seems to rely on access to globals or something - that kind reduces the sphere to which QuickForm can be used for.

HTTP_Upload, DB_Pager, Mail - no idea.

Overall, quality in PEAR varies - there's some great stuff and some that needs work. Really we should submit refactorings to the developers - in many cases it should be well received. Also if the lead developer has gone quiet, you may be able to take over running a PEAR package.

PEAR packages in general save you development time but may cost you later - really you need is to research in spare time and find what you like - that means reading source code.

Also most PEAR code is not designed for performance (today). E.g. 90% start with;

PHP Code:

require_once 'PEAR.php'; 

That one line adds about 1000 lines of code for PHP to parse.

Overall I've grown to like PEAR but in some cases, it does need work. Best is to get involved and see if you can change things. The current leaders of PEAR are aware of the weaknesses and open to suggestions for improvment (or better yet offers to help with coding).
HarryF is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 01:56.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved