[PHP-DB] SQL or array ?

2005-04-23 Thread Paul Reilly

I have a quick question about which would the best way to implement
something in terms of performance. Using a database, or just creating
a big array in memory?

I have a PHP file manager script which creates an array of all
files in a directory, and get's their mime types. It then prints
these files to the browser with a little image or a word icon etc
for word documents.

So the data looks a bit like this:

+--++---+--+
| id   | mime_type  | description   | icon |
+--++---+--+
|0 | text/html  | HTML document | html.png |
|1 | application/msword | Word document | word.png |
+--++---+--+

But this means for every file it comes across it needs
to do an SQL query to find the description and icon name.
Which doesn't seem very efficient.

Would it be better to just create a big array at the start
of my script with all this data in? That would seem more
efficient, and hence faster way of doing it?

Any feedback appreciated.

Paul

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



Re: [PHP-DB] SQL or array ?

2005-04-23 Thread Mark Cain
explain the phrase big array.

What is big to you might not be big to the server nor to me but then again
maybe it's bigger.  Are you talking dozens, hundreds, thousands, millions??

- Original Message -
From: Paul Reilly [EMAIL PROTECTED]
To: php-db@lists.php.net
Sent: Saturday, April 23, 2005 5:05 PM
Subject: [PHP-DB] SQL or array ?



 I have a quick question about which would the best way to implement
 something in terms of performance. Using a database, or just creating
 a big array in memory?


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



Re: [PHP-DB] SQL or array ?

2005-04-23 Thread Paul Reilly

 explain the phrase big array.

I guess everything is relative!
We're talking about 300-500 items here.

Paul

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



Re: [PHP-DB] SQL or array ?

2005-04-23 Thread M Saleh EG
Only? That aint too big, but now i'm confused what's ur hardware and
O.Sspecs? 300 to 500 would be a peice of cake to load. However, it
depends on
ur system.

I would rather use the array than hitting the db for the query. Because the 
bottom line is that you will receive your data in an array no matter what 
even if its in the db so doesnt realy matter unless you wanna paginate it. 
In that case I'd use the db rather to array alone. 

Wow Hold on. That's a catch 22. If ur loading ur array in the beginning of 
the execution then just do it on the DB once n just load it the next time. 
That means the next time you dont have to take a trip to ur file system n 
then another trip to display the array. And plus if u needed to paginate 
which of corse ull need to for such a number db helps, however paginating 
arrays is easy as well.

HTH

Benchmark it! And find out for yourself.

On 4/24/05, Paul Reilly [EMAIL PROTECTED] wrote:
 
 
  explain the phrase big array.
 
 I guess everything is relative!
 We're talking about 300-500 items here.
 
 Paul
 
 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


-- 
M.Saleh.E.G
97150-4779817