开发者

Is saving enormous user information into a MySQL table good if one wants to display it for later use?

I have a file named discussion.php, where a form is located. In this form, a user will enter information, and the information will be posted to savedisc.php. Below is the code for discussion.php:

<form action='savedisc.php' method='post'>
  <p>What would you like to discuss?</p>
  <textarea name='message' rows='15' cols='40'></textarea>
  <input type='submit' value='Submit' />


</form>

Once the user hits the submit button, the text that the user had typed should be saved via savedisc.php. I.e. I will connect to the database, and save what the user had typed in textarea.

Now to display the information that the user had typed in the textarea, I will connect to the database in anothe开发者_StackOverflow中文版r file, and show the appropriate content.

Some of my questions are: Should I not save it in the database? Because later on I might have enormous amounts of data in my tables. Is there another way to display information submitted by a user without the use of saving to the database? Or am I doing OKAY? For example, the question I am about to post right now, is it actually saved in a database?

Thank you.


Yes! Databases are good at storing large quantities of data, so you're fine!

As long as you do proper validation of data*, go right ahead!

* - Look up mysql_real_escape_string


MySQL is perfectly capable to handle tables with several gigabytes of data. I doubt this will ever be a problem.

The alternative being to store the data in flat files, it's clearly better to use MySQL for this purpose.


Databases are meant to store large amount of data and handle large amount of transactions. So, definitely yes.

But if you're thinking of optimizing your database and save some resources, you can store the data the user just entered and show it without requesting it again from the database, like when you ask a question and it shows it to you again on Stack Overflow, you'd have one less transaction.

So, for example in your savedisc.php

<?php
$message = $_POST['message'];
StoreInDB($message); // some function to store data
echo $message; // this is useful when you want to immediately
               // show the user the information they entered
?>


yes, that's an entirely appropriate use of a database. An exception might be if If the size of each piece of text is very large, like 10 or 50 or 150kb, in which case you might consider storing it as files and storing file metadata in the database.


Most CMSes use a database backend to store the actual text and markup for their stories; large sites such as the New York Times and the Washington Post use databases to store their stories, so that they can be searched and cross-referenced as necessary. While it is possible to do all of that as files in a filesystem, modern databases are optimized for these sorts of operations.

One thing you'll need to do is to choose the type of table and datatype to use for storing your data. MySQL provides several storage engines for creating tables (InnoDB and MyISAM are the most popular). As for data types, CHAR and VARCHAR are good for relatively small amounts of text, with TEXT being suitable for large amounts of text. (If you're storing raw binary data, like images, instead of text, then you'll be more interested in BINARY, VARBINARY, and BLOB).

Each storage engine and datatype will provide different trade-offs for performance and functionality, but for relatively small and simple applications, MyISAM and either VARCHAR or TEXT will be a good choice for your needs.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜