English 中文(简体)
如何在MySQL中存储文章?
原标题:How to store an article in MySQL?

I would like to store some articles (blog posts) in a mysql table, these posts will be made from more parts (e.g.: part1, part2 ... part x) I don`t know how to store them... Could I store each part in a text file, or how could I store it in a mysql database ? What field can support data of this size ? And how should I design the table to store each part of the post ? It would be good to store each part in the same cell and just separate them with a word () and then cut it with php ?

谢谢

最佳回答

我建议使用一个表“Post”和第二个表“Post_part”,其中FK为“Post”。在“Post_part”表中,可以将文本存储在text类型的列中。

问题回答

一种常见的设计方法是创建一个“零件”表,例如:

CREATE TABLE parts (page_id INTEGER, part_name VARCHAR(255), body TEXT);

这将在较低的流量下工作良好。(在这种情况下,page_id是“拥有”该部分的页面的外键-您可以通过说natch<code>SELECT*FROM parts WHERE page_id=:some_page_id

随着流量的增加,插入和组装页面的成本可能会变得惊人,在这种情况下,将正文内容从更大的文本字段中分离出来(正如你所建议的)并不是一个可怕的想法。在这个级别上,将哈希直接序列化到数据库列中,并使应用程序服务器的CPU承受工作的冲击(而不是数据库服务器),从而获得的速度收益可能是值得的。

您感兴趣的列类型在“字符串类型的存储要求”下枚举:http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html

总之,TEXT(64KB)应该足够大,可以容纳大多数基本数据。MEDIUMTEXT(16 MB)或LONGTEXT(4096 MB)(如果您的数据明显较大或预计会增长)。BLOB、MEDIUMBLOB或LONGBLOB(与*TEXT类型大小相同)(如果您打算从DB列进行任何PHP变量反序列化)。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签