Jump to content

Flat File Vs Sql Database?


Recommended Posts

In terms of server load, what's the difference between calling information from a flat text file (using PHP's include() or readfile() functions) and putting the same information in a database and using SQL queries?


I'm not thinking about complex information here -- just basic text like an about or copyright page might have.

Link to comment
Share on other sites

I would think that pulling the data through a MySQL query would put more load on the server and take longer to execute that just reading a plain file directly from the disk.


MySQL table data is also stored in files on the disk. But to get that data and send it to a browser, the web server must open a connection to the MySQL server, submit a request (MySQL query) for the data, wait for the database server to process the query and retrieve the data, receive the query result from the MySQL server, and finally read the data from the returned query result.


You have none of this overhead if you just read the text directly from a file on disk.


There may be other reasons why you'd want this data stored in your database instead of in a disk file, but speed/resources wouldn't be one of them. ;)

Link to comment
Share on other sites

If the data is part of a larger thing, for instance, "Hi _Jim_ you last logged in on _September 10_," then a database would be better than searching through 100,000 lines of a text file.


If it is simply an include such as many sites have for copyright notices then a flat file containing only that info would be hugely better.


SQL databases rule when you have to look up a piece of data from within 1000's but only after they get to a certain size - if you have 3 names a flat file would be quicker - if you have 300 then SQL may be... it all depends on the type of data.

Link to comment
Share on other sites

I side with Jim here. This will depend mostly on the amount of data you have and the number of components in this "data". A flat file will handle a simple data file of one or two components very quickly, say name and sex. But when you have lots of components, name, age, sex, address, shoesize, etc...this is where a database wins hands down. A database uses indexing which speeds up the search and breaks the search down to just the component you want (sex), where a flat file will need to search every character.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...