5

I insert about 1.1 Mb of Data into a Mysql Field of type LONGBLOB. This is far away from the maximum supported length of a LONGBLOB field.

The insert seems to work.

If I do a strlen($data) before inserting it returns 1059245.

If i do a query after inserting:

SELECT OCTET_LENGTH(`data`)...

It returns 1059245

But if i do

$stmt = $pdo->prepare("SELECT `data` FROM `tbl_mytable` WHERE `id` = :id LIMIT 1");
$stmt->bindValue(":id", $id, PDO::PARAM_INT);
$stmt->execute();
$data = $stmt->fetch(PDO::FETCH_ASSOC);
echo strlen($data['data']);

it returns 1048576

My data seems to be cutten after 1048576 bytes.

Why do I only receive the first 1048576 bytes of my data when doing a query?

Is it a PDO Configuration, something like max_fetch_length?

steven
  • 4,868
  • 2
  • 28
  • 58

1 Answers1

9

It was the MYSQL_ATTR_MAX_BUFFER_SIZE which is 1MB by default.

This fixed the issue:

    $pdo->setAttribute(PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, 1024*1024*50);  // 50 MB      
steven
  • 4,868
  • 2
  • 28
  • 58
  • For some reason I have to set this in the constructor using the optional 4th parameter - it doesn't work directly using the above code. – Jon Marnock May 18 '15 at 07:15