Question

I need to store and update a very large text into MySQL database. I took the input via form textarea. but the MySQL query seems to fail to execute if the text is too large. Is there any efficient way to store long texts via PHP-MySQL? I am using LONGTEXT as the field type.

Should I store it via LONGBLOB? If yes, then how to retrieve the text via PHP and display for editing purpose?

Was it helpful?

Solution

Few things could go wrong here.

You need to use POST instead of GET while posting form data.

If data is successfully posted escape text before inserting it into the db with:

mysql_real_escape_string($some_text)

LONGTEXT is just fine for longer text. You don't need LONGBLOB unless you are using binary data (like pictures etc.)

Worst case scenario use some ORM to do the same thing. It will take you some time to configure it to work with your PHP and MySQL but it will save so much time on long run. A good example is Propel.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top