0

In my code, I use the variable $content. It's a text string with a length of ~200000. $session doesn't matter in this case. If i try to insert the following data, ...

$c = mysql_real_escape_string($content);

mysql_query("
  INSERT INTO data (time, session, key_, value_) 
  VALUES('".time()."', '".$session."', 'content', '".$c."')
");

...a new row is generated in the DB and time, session, key_ and value_ are written. But when $content had a length of ~200000, the inserted text is only a fragment of the first ~1300 characters. The field type is set to longtext, collation is utf8_bin.

If i choose $c = strlen(mysql_real_escape_string($content));, something about '200000' is written to value_. There is no mysql_error in any case.

So why is only a "short" fragment of my variable inserted?

edit:

To avoid this problem, I used base64_encode(), to encode all data and the query did its job.

Fidelis
  • 339
  • 1
  • 4
  • 11
  • 1
    Can you give the describe result of the table? – ddinchev Jun 12 '12 at 10:20
  • 1
    As stated in the PHP manual for the [`mysql_query()`](http://php.net/manual/en/function.mysql-query.php) function: *Use of this extension is discouraged. Instead, the [MySQLi](http://www.php.net/manual/en/book.mysqli.php) or [PDO_MySQL](http://www.php.net/manual/en/ref.pdo-mysql.php) extension should be used. See also [MySQL: choosing an API](http://www.php.net/manual/en/mysqlinfo.api.choosing.php) guide and [related FAQ](http://www.php.net/manual/en/faq.databases.php#faq.databases.mysql.deprecated) for more information.* – eggyal Jun 12 '12 at 10:31
  • Describe result is: [Field] => time [Type] => int(15) [Null] => NO [Key] => [Default] => [Extra] => [Field] => session [Type] => varchar(32) [Null] => NO [Key] => [Default] => [Extra] => [Field] => key_ [Type] => varchar(100) [Null] => NO [Key] => [Default] => [Extra] => [Field] => value_ [Type] => longtext [Null] => NO [Key] => MUL [Default] => [Extra] => @eggyal: Thanks a lot, I'll try it. – Fidelis Jun 12 '12 at 10:54
  • Try again - this time just using html safe ascii – symcbean Jun 12 '12 at 11:33
  • @eggyal:I tried MySQLi, but nothing changed. – Fidelis Jun 12 '12 at 21:48

2 Answers2

0

check the type of the field in the database, what type are you using ?

0

Try to set field type to TEXT .

BebliucGeorge
  • 751
  • 2
  • 8
  • 15