简体   繁体   English

Kohana PHP,ORM和MySQL BLOB

[英]Kohana PHP, ORM and MySQL BLOBs

I'm trying to create and retrieve a BLOB in a MySQL table via Kohana's ORM library. 我正在尝试通过Kohana的ORM库在MySQL表中创建和检索BLOB。

The code looks something like: 代码看起来像:

$attachment = new Attachment_Model();
$attachment->name = $info['FileName'];
$attachment->size = strlen($info['Data']);
$attachment->data = $info['Data'];
$attachment->mime_type = $info['content-type'];
$attachment->save();

I've verified that the data is OK at this point by outputting it to a file. 我已经通过将数据输出到文件来验证数据是否正常。 However, when I retrieve the data it comes out corrupted. 但是,当我检索数据时,它会被破坏。 I've managed to narrow this down a bit more - I've used the MySQL query tool to extract the data as held in the database and I can verify that the data in the database is corrupt, so the problem must be on the INSERT. 我已经设法缩小了一点 - 我已经使用MySQL查询工具提取数据库中保存的数据,我可以验证数据库中的数据是否已损坏,因此问题必须在INSERT上。

Also, the files inputted aren't always corrupt - smaller files (such as images) tend to be OK. 此外,输入的文件并不总是损坏 - 较小的文件(如图像)往往是正常的。

Anyone have any ideas? 有人有主意吗?

It turns out that, in this case, I was using the BLOB data type. 事实证明,在这种情况下,我使用的是BLOB数据类型。

The BLOB data type truncates data at 65535 characters (silently, without throwing an error!) BLOB数据类型以65535个字符截断数据(静默地,不会抛出错误!)

I've upped it to a MEDIUMBLOB (which has a max length of 16777215 characters), and it seems to work OK! 我把它升级为MEDIUMBLOB(最大长度为16777215个字符),它似乎工作正常!

猜测,但是:可能是因为kohana模型层将所有数据作为字符数据而不是二进制数据插入,这会在保存/检索BLOB对象时造成麻烦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM