# Mysql/pdo vs fread()

**URL:** <https://forum.kirupa.com/t/mysql-pdo-vs-fread/261255>\
**Category:** Uncategorized\
**Created:** [May 25, 2008, 3:01am UTC](https://forum.kirupa.com/t/mysql-pdo-vs-fread/261255 "2008-05-25T03:01:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [May 25, 2008, 3:01am UTC](https://forum.kirupa.com/t/mysql-pdo-vs-fread/261255/1 "2008-05-25T03:01:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Templarian](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/templarian/32/7152_2.png) [@Templarian](https://forum.kirupa.com/u/Templarian)\
**Post date:** [May 25, 2008, 3:19am UTC](https://forum.kirupa.com/t/mysql-pdo-vs-fread/261255/2 "2008-05-25T03:19:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [May 25, 2008, 3:28am UTC](https://forum.kirupa.com/t/mysql-pdo-vs-fread/261255/3 "2008-05-25T03:28:24Z")

</div>

You are misunderstanding me. I know that.

I am storing all the information in a database, that wasn’t part of the question 😃 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)

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [May 25, 2008, 8:57pm UTC](https://forum.kirupa.com/t/mysql-pdo-vs-fread/261255/4 "2008-05-25T20:57:02Z")

</div>

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.
