Best way to save large file for request

I have a text file for an English dictionary with over 450,000 words. Before I saved it in a text file, it worked fine. But now I downloaded a new dictionary with the same number of words, but with their meanings. I just want to ask some experienced person what would be the best way to keep this without slowing down the site? Should I save it in a text file on the server or will it be saved in the database now? What are the benefits of saving to a database and saving to a text file or vice versa?

+4
source share
3 answers

Definitely use a database. It:

  • easier to query (just use the MySQL PHP library instead of trying to parse the text)
  • easier to maintain (there are many great database management tools)
  • faster [1]

[1] In your situation, the database can be much faster, because it seems that you will be doing a lot of reading. Some database systems cache frequently used queries for quick response.

A text file has its advantages (for example, it may be easier to back up, the search for words in a text file is not susceptible to SQL injection attacks). However, if they are executed correctly, the database is much more suitable for something like that.

+1
source

At any time, when you refer to large amounts of information, it is best to interact with the database. The database will help reduce your bandwidth for one, you do not require users to access a large text file.

+1
source

Gurnor

Could you explain a little more how I can avoid sql injection attacks on the database? And why did you say that the text file is prone to this?

Well, if you use a text file, there is no database, so there is no way to do SQL injections. Here's a good link showing simple sql injection examples and ways to prevent them:

http://www.tizag.com/mysqlTutorial/mysql-php-sql-injection.php

0
source

All Articles