我将大约 1.1 Mb 的数据插入到 LONGBLOB 类型的 Mysql 字段中.这与 LONGBLOB 字段支持的最大长度相差甚远.
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.
插入似乎有效.
如果我在插入之前执行 strlen($data)
返回 1059245.
If I do a strlen($data)
before inserting it returns 1059245.
如果我在插入后进行查询:
If i do a query after inserting:
SELECT OCTET_LENGTH(`data`)...
返回 1059245
但是如果我这样做
$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']);
返回 1048576
我的数据似乎在 1048576 字节后被截断了.
My data seems to be cutten after 1048576 bytes.
为什么我在查询时只收到数据的前 1048576 个字节?
Why do I only receive the first 1048576 bytes of my data when doing a query?
它是 PDO 配置,类似于 max_fetch_length 吗?
Is it a PDO Configuration, something like max_fetch_length?
MYSQL_ATTR_MAX_BUFFER_SIZE 默认为 1MB.
It was the MYSQL_ATTR_MAX_BUFFER_SIZE which is 1MB by default.
这解决了问题:
$pdo->setAttribute(PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, 1024*1024*50); // 50 MB
这篇关于获取时Mysql PDO最大LONGBLOB数据长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!