4

I've been using Zend Framework for quite a while now, but now I have an issue that's got me puzzled. I have a table (MySQL) with just 2 columns (id and msg). The id field is an auto increment value and the msg field is a longtext type.

The following code should work just fine for inserting a record into the table:

$t = new Zend_Db_Table('table1');
$id = $t->insert(array('msg' => $content));

Whenever $content is just a plain string value like 'blah', it works just fine, like it should. But the fieldtype is not a longtext type for no reason, the content will be quite large. So now I try to place about 14kb of data in $content, no exception occurs, the database insert seems to have worked, but only for the first 6kb. The rest of the data is just gone?!

When I try to use to oldfashioned mysql_connect, mysql_query, etc routines, it all works like a charm. So it's really seems to be a Zend framework issue... Has anybody else experienced this?

George Netu
  • 2,758
  • 4
  • 28
  • 49
vinnie
  • 41
  • 1
  • What type of data is `$content`? Is it plain text or can it be binary? Also, what Db adapter are you using (e.g. PDO Mysql) – drew010 Mar 02 '12 at 19:55
  • My bad. I'm inserting utf8 encoded html in the field while using PDO MySQL. The Zend Framework is version 1.11.10. – vinnie Mar 02 '12 at 22:39
  • Are you trying to insert the same data? Or is this happening for various $content variations? – Mike Purcell Mar 03 '12 at 03:40
  • See if changing the column type to either `LONGBLOB` instead of `LONGTEXT` helps, or change the collation of the `LONGTEXT` column to `utf8_bin` and see if that helps. – drew010 Mar 03 '12 at 21:03
  • I'm inserting the same data, but I just tested it with different data, same problem... Longblob, longtext and collation change did not have any effect either... More thoughts on this issue? – vinnie Mar 04 '12 at 19:37
  • Large text insert totally works for me. Try inspecting the query after you do the insert. You can get it like this `echo $table->getAdapter()->getProfiler()->getLastQueryProfile()->getQuery();` See if the large text in query is in full. – Weltschmerz Mar 07 '12 at 15:27
  • It might also be an idea to double check that `$content` hasn't been truncated *before* it it reaches the `insert()` statement. Just a thought. BTW - I just tried your code with ZF 1.11.11 and MySQL 5.1.54, the only difference being that I replaced `$content` with a call to `file_get_contents()` to read a 45KB image file and it worked fine. (The `msg` column was a `MEDIUMBLOB`.) – JamesG Mar 09 '12 at 01:13
  • Sorry for the delay, been absent for a while... @namesnik: Just tried what you suggested, but with no luck. When I try to get the exact query, I see it like this: INSERT INTO `debug` (`msg`) VALUES (?) When I aks for the QueryParameters, it returns the full data, as it is supposed to... @JamesG: I will give this a try and see what happens... – vinnie Apr 26 '12 at 07:42
  • @JamesG: apparently when inserting into a mediumblob cell everythings works like a charm!! Is there something wrong with the mediumtext type?? – vinnie Apr 26 '12 at 08:13
  • Very strange. I just repeated the experiment with the `MEDIUMTEXT` type and it worked OK. If you don't need case insensitivity for searching then maybe just go with the `MEDIUMBLOB`? I'm just wondering if the data you're trying to insert has some string termination characters that are telling some intermediate code (eg. the mysql driver) to stop at some point. Ultimately, I don't think this is a Zend Framework issue - I'd say it has something to do with your mysql/pdo module(s). – JamesG Apr 30 '12 at 07:31
  • If what you're saying is correct, then why would it work correctly using the mysql_* native functions? These make use of the pdo modules also, right? – vinnie May 05 '12 at 07:17

1 Answers1

0

Configuration

  • Zend Framework v1.11.10
  • Zend_Db_Table is configured with the PDO_MYSQL adapter
  • MySQL database table two columns; id (autoincrement)

Issue

  • Attempting to INSERT 14kb of UTF8-encoded HTML into longtext column
  • Zend_Db_Table truncates the data at 6kb

Tests

  • mysql_query can INSERT the same data without issue
  • Zend_Db_Table can SELECT all the data without issue
  • setting error_reporting(-1) reveals 'no errors, warnings or notices'
  • mediumblob works fine

Isolating the issue

  • Change the column to a mediumtext. Does the insert work now?
  • Have you checked what the query actually looks like? See comment above from namesnik.
  • How many bytes get written on the failed inserts? Is it consistent?
Tim
  • 2,383
  • 1
  • 15
  • 19
  • This really is an INSERT issue, for sure! I can tried a regular, old fashioned SQL INSERT statement (with mysql_connect, mysql_query, etc) and when I use the same code to read the value from the database, everything works just fine. – vinnie Mar 12 '12 at 15:34
  • Updated the answer with better structure; please try out some of the suggestions under 'Isolating the issue'. – Tim Mar 15 '12 at 19:21
  • Thanks... I just did what you asked me. error_reporting(-1) had no result, no errors, warnings or notices, not on the screen and not in the logs. Changing column type to mediumtext didn't help. I tried to get the actual query, but it left out the params. When asking only for these params, these seem to be just fine. Exactly 8.00 KB are written to the database... – vinnie Apr 26 '12 at 08:06
  • Inserting into mediumblob seems to work just fine... But as I'm very stubborn, I would really like to use the mediumtext ;-) – vinnie Apr 26 '12 at 08:14
  • This is understandable, I was just hoping to isolate the issue down to one specific data type. So it sounds like both `mediumtext` and `longtext` are broken, and everything else works fine? – Tim Apr 26 '12 at 17:08
  • That's correct... Alle the 'text' data types seem to be broken... Is that a know problem, or am I the only one experiencing this? ;-) – vinnie Apr 27 '12 at 07:10