View Full Version : MySQL query or fread?

09-06-2011, 10:37 PM
So lets say my script always connects to the MySQL database at beginning of script.

Now, what would be faster to obtain data?
a) Selecting all data from a table with 20 entries
b) fopen-ing a file and fread-ing it (both binary; 80 chars); also 20 entries.

09-06-2011, 10:41 PM
Depends but if MySQL has the query cached it could be a lot faster. You can time PHP code, your best bet would be to write both and time them. Does any other parts of the page require data from your database? If so the connection time is going to be a cost either way.

For timing your code see: http://php.net/manual/en/function.microtime.php