开发者

Problem inserting a long text in database column MYSQL PHP

I am having a problem inserting a long text (around 9000 characters) with an INSERT query in php. I have already tested changing the column type (TEXT, MEDIUMTEXT,LONGTEXT) even thought TEXT type should do for 9000 chars. Also tested with a text free of any special chars or quotes.

I print my query and looks ok so I copy and paste in开发者_开发技巧to phpMyAdmin and the row inserts correctly. So the problem is coming when I try to INSERT from my php class.

I tested with a smaller text and this seems to work ok. I really need to get this solved. If anyone has the solution please let me know. Thanks!


I haven't yet found what is the problem inserting my long texts, but I have found a solution to turn around it, it is not very clean but at least it will work until I found the real problem, just in case anyone has the same issue this is what I did.

Split the text in peaces of 1000 chars, do my INSERT and the UPDATE the text field in the data base adding the peaces of text, so the code :

$textArray = str_split($text,1000);

foreach($textArray as $t){ $model = new Article_Model_UpdateText($id,$t); }

The query in Article_Model_UpdateText looks like this :

"UPDATE mg_articles SET text = CONCAT (text, '".$text."') WHERE idArticle = ".$id.";";

Hope this helps someone, thanks for all your replies.


Try with the Datatype BLOB or LONGBLOB in mysql.

It will do your work.


My crystal ball suggests the issue may be related to max_allowed_packet:

http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_max_allowed_packet

(But it's just a blind shot.)


you should use mysqli_real_escape_string for storing long texts...it will be like

$variable= mysqli_real_escape_string(connection_variable,user input long text);

now you can store the $variable in your database by insert query, you should be storing $variable in longtext field in the database

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜