is it better to query database or grab from file? php & mysql

Posted by pfunc on Stack Overflow See other posts from Stack Overflow or by pfunc
Published on 2010-05-05T16:58:16Z Indexed on 2010/05/05 17:58 UTC
Read the original article Hit count: 192

Filed under:
|

I am keeping a large amount of words in a database that I want to match up articles to. I was thinking that it would just be better to keep these words in an array and grab that array whenever needed instead of querying the database every time (since the words won't be changing that much).

Is there much performance difference in doing this?

And if I were to do this, how to I write a script that writes the array to a a new php file. I tried writing the array like so:

while( $row = mysql_fetch_assoc($query))
{

 $newArray[] = $row;

}


$fp = fopen('noWordsArr.php', 'w');
fwrite($fp, $newArray);
fclose($fp);

But all I get in the other file is "Array".

So i figured I could write this and then write have a chron hit up the file every few days or so in case things have changed. But I guess if there is no performance advantage then it prob won't be necessary and I can just query the database every time I need to access the words.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql