Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql PDO maximum LONGBLOB data length on fetch

Tags:

php

mysql

pdo

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?

like image 849
steven Avatar asked Jul 16 '14 13:07

steven


1 Answers

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      
like image 70
steven Avatar answered Nov 04 '22 13:11

steven