Re: OOP slow -- am I an idiot?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Chris de Vidal wrote:
I think perhaps I'm using classes and OOP incorrectly.  The last time I used them, they were slow.

The examples you provided shows that it's not OOP that's the problem, it's how your getting the data as you suspected.

Doing tons of queries is going to be slow whether you're using OOP or functional programming.

Depending on your app, you could pass in arrays of data:

getRevenue($customer_id, $departments=array(), $years_to_fetch=array()) {
... sanitize $departments and $years_to_fetch

$query = "SELECT revenue FROM customer_revenue WHERE customer_id = '$customer_id' AND department IN (" . $departments . ") AND year IN (" . $years_to_fetch . ")";
}

Because php is loosely typed you can take advantage of that.

Only want to pass in one department? Change it to be an array and go from there:

if (!is_array($departments)) {
  $departments = array($departments);
}


Depends a lot on the situation as well. If it's for a report that's going to be run once a year, a few extra queries probably isn't going to make any difference. Something that gets called every time? Optimize it as much as possible.

I've used both methods and they both have their merits.

Context is important too :) If I need to create a "queue" of items to go through (eg the web interface creates a queue for a cron job to pick up and process), then I'll do everything straight in the database and nothing in PHP (well as much as possible anyway) by passing in everything I need and writing a query to handle it all.


After all that, I probably didn't help much ;)

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux