Re: OOP slow -- am I an idiot?

From: Date: Wed, 11 Oct 2006 01:19:58 +0000
Subject: Re: OOP slow -- am I an idiot?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-242948@lists.php.net to get a copy of this message
On 10 Oct 2006, at 4:14 PM, Chris de Vidal wrote:
I think perhaps I'm using classes and OOP incorrectly. The last time I used them, they were slow. I want to create a "customer" class which fetches its attributes from a MySQL database. Something like this pseudocode: class customer
    {
    ...
    getName ($id)
        {
        $result = mysql_query ("SELECT name FROM customers WHERE id = '$id'");
        return mysql_result ($result, 0);
        }
    getRevenue ($id,$department,$month,$year)
        {
        $result = mysql_query ("SELECT revenue FROM customer_revenue WHERE customer_id = '$id' AND
department = '$department' AND month = '$month' AND year = '$year'");
        return mysql_result ($result, 0);
        }
    ...
    }
You should look into getting Professional PHP5 by Lecky-Thompson, Eide-Goodman, Nowicki and Cove from WROX. It's a good introduction to using PHP5 with design patterns to solve problems similar to yours. Plus, the knowledge can be applied to other object oriented programming languages, not just PHP5. It's also been out for a while so it may be in the sale section already. The collection class in chapter 5 discusses a programming problem just like yours. Johan Martin Catenare LLC 534 Pacific Ave San Francisco, CA. 94133 http://www.catenare.com http://www.linkedin.com/in/catenare

« previous php.general (#242948) next »