Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to store multiple lines of data in MySQL?

I'm looking at storing multiple lines of data in MySQL (or your choice), an example would be a poem. I wouldn't know how many lines it could be and I have to keep its structure intact so when I go display it to my end users on a site it is properly formatted.

I could be storing anywhere between 100 characters to 100,000. I'd rather shy from using plain text unless someone can help me figure out an easier method.

like image 649
Matthew Avatar asked Nov 04 '22 17:11

Matthew


2 Answers

If you store the text in a simple format like Markdown then you can render it as HTML using any number of libraries that convert.

There's nothing wrong with storing large amounts of text in MySQL. For data over 1KB you should be using TEXT for up to 64KB or LONG TEXT for much larger amounts.

VARCHAR can go to longer lengths under newer versions of MySQL but it's probably not what you intend here.

like image 69
tadman Avatar answered Nov 08 '22 15:11

tadman


If you're really worried about the formatting. You could also use a content editor that creates html code like <br/> and lists for formatting. Then post that into your sql as a text.

Again, I'm not sure exactly if your worried about inputting data into mysql, or worried about displaying it from mysql (Hence, the content editor idea).

like image 28
Jared Drake Avatar answered Nov 08 '22 15:11

Jared Drake