Mysql/pdo vs fread()

I know this might seem obvious, I just want to make sure.

The process of looping a database and writing a blank file with fopen and fwrite versus reading a file with fread/fopen, appending to it (at the top, with seek).

Obviously at small filesizes fopen/fread will be faster than sql/pdo looping but I’m wondering if that fact stays the same when the amount of data grows to somewhat large proportions.

Any clues?

I benchmarked pdo looping vs fread/fwrite and it takes 4 ms to loop from db and write it versus 0 ms with fread/fwrite if there is 50 records in the table (10Kb of text data).

Wondering what would happen if I had 5.000 records. : ) anyone know?

oh and edit: for the purpose there’s no security issue whatsoever. Just plain raw speed.

You use a database because you can recover data and back it up. The way a database works in theory is much different than a flat file system (if you want that btw use SQLite).

I think I’ll let a CS major explain it as I don’t know all the technical lingo.

You are misunderstanding me. I know that.

I am storing all the information in a database, that wasn’t part of the question :smiley: Sorry if that sounded *****y btw, not my intention. I’m asking for a bench between a 5.000 record database loop and a file that matches its filesize (fopen/fread)

Little update for anyone who might be interested…

1200 records vs a file dump of the record (84Kb).

PDO: 34 ms
Fopen 19 ms

Seems it’s just consistently faster I guess.