Flat File Vs Sql Database?

liunx

Guest
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?<br /><br />I'm not thinking about complex information here -- just basic text like an about or copyright page might have.<!--content-->
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.<br /><br />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.<br /><br />You have none of this overhead if you just read the text directly from a file on disk.<br /><br />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. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" /><!--content-->
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.<br /><br />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.<br /><br />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.<!--content-->
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.<!--content-->
I wonder what Freud would say about your last sentence, Bob. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/tongue.gif" style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" /><!--content-->
Guess you know where my mind was <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/naughty.gif" style="vertical-align:middle" emoid=":naughty:" border="0" alt="naughty.gif" /><!--content-->
Thanks, guys! That confirms what I was thinking--but it's good to know why.<!--content-->
 
Back
Top