Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TXT File or Database?

What should I use in this case (Apache + PHP)? Database or just a TXT file? My priority #1 is speed.

Operations

  • Adding new items
  • Reading items
  • Max. 1 000 records

Thank you.

Database (MySQL)

+----------+-----+
| Name     | Age |
+----------+-----+
| Joshua   | 32  |
| Thomas   | 21  |
| James    | 34  |
| Daniel   | 12  |
+----------+-----+

TXT file

Joshua 32
Thomas 21
James 34
Daniel 12
like image 742
Ruth Rettigo Avatar asked May 23 '10 22:05

Ruth Rettigo


People also ask

Is text file a database?

Yes you can use a . txt file as a database but you should make it a lot easier on yourself in the long run and learn mySQL in a couple of hours so you are doing it more along the lines of industry standards.

Should I use a database or a text file?

The primary advantage of a database vs a text file or an single data file (aka a flat file) is that a database allows you to capture relationships across single data files.

Why is a database better than a text file?

The three main advantages that databases have over other, simpler data storage systems (such as text files and spreadsheets) are access, integrity, and security.

What kind of file is txt?

A file with . TXT extension represents a text document that contains plain text in the form of lines. Paragraphs in a text document are recognized by carriage returns and are used for better arrangement of file contents.


1 Answers

For speed and optimized memory usage, I'd say go with a database hands down. Putting an index on the name column alone will probably boost performance in a way never achievable with a text file.

A database has also other advantages like some sanitation (no breaking of delimiters, newlines etc.) and less danger of access conflicts when multiple instances try to read from the table - and different from a file-based approach, writing conflicts are constrained to the record in question only.

like image 69
Pekka Avatar answered Oct 29 '22 04:10

Pekka