开发者

How to store .txt files MySQL database?

Can I store data files (e.g开发者_如何学Python. txt files) to the MySql server? If I can, how to store them?


You can use LOAD DATA INFILE to read the contents of a file and store it in a table in the database in a structured format.

This can be considerably faster than reading and parsing the file on the client and then using multiple INSERT statements.

Example:

LOAD DATA INFILE 'data.txt' INTO TABLE db2.my_table;


Yes you can, but you would probably be better off storing them on the file system and storing a path to the file in the DB.

There are a few SO Posts that discuss this:

  • Storing Images in DB - Yea or Nay?
  • Storing a file in a database as opposed to the file system?


Sure you can. I would suggest reading the data from your files and then saving it in your database, i would say in a text field.

You can use something like this to get the file's content:

$file = file_get_contents('./yourfile.txt');

Then insert it

Insert into myTable VALUES (mytextfile = $file)


How much text are we talking about here? If there's not that much text, you can store just the content of the file in the database.

You can also store the file itself as a BLOB. http://dev.mysql.com/doc/refman/5.5/en/blob.html

If you'll be dealing with many files, you'll probably be better off storing the files on your sever with the file path in the database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜