PDO Blob插入缺少的数据


PDO Blob Insert Missing Data

我正在利用phantom来捕获图像,然后将它们上传到一个集中的MySQL数据库。

我遇到的问题是,它一直在切断我尝试和推送的每个文件的末尾。不管是.pdf、.png、.docx、.xlsx……它都会剪切掉文件的一部分,从而损坏文件。奇怪的是,它总是从每个文件中剪切相同的数量。

我的SQL插入代码是:

$put_linkdata = $DBW->prepare('INSERT `'.$tableD.'` SET
                    captured = :capture_time,
                    error = :eYN,
                    link = :link,
                    image = :image,
                    html = :html,
                    `text` = :plaintext,
                    file = :file,
                    mimetype = :mimetype');
                $put_linkdata->bindValue(':capture_time', date('Y-m-d H:i:s',$record['timestamp']));
                $put_linkdata->bindValue(':link', $item['url']);
                $put_linkdata->bindValue(':mimetype', $record['mimetype']);
                $put_linkdata->bindParam(':eYN', $record['error'], PDO::PARAM_STR);
                $put_linkdata->bindParam(':image', $record_child['image'], PDO::PARAM_LOB);
                $put_linkdata->bindParam(':plaintext', $record_child['text'], PDO::PARAM_LOB);
                $put_linkdata->bindParam(':html', $record_child['html'], PDO::PARAM_LOB);
                $put_linkdata->bindParam(':file', $record_child['file'], PDO::PARAM_LOB);
                if($put_linkdata->execute()){
                    $linkData_record['id'] = $DBW->lastInsertId();
                    print PHP_EOL.mb_strlen($record_child['image'], '8bit');
                    print PHP_EOL.PHP_EOL.'~~~~~~~~~~~~~~~~~~~~~~~~~~~'.PHP_EOL.PHP_EOL;
                    die();
                }
                else{
                    throw New Exception('Error inserting linkdata record into archive - SQL error "'.$put_linkdata->queryString.'"'.PHP_EOL.PHP_EOL.$put_linkdata->errorInfo());
                }

我已经运行了大量的测试,在此之前,数据仍然保持完整性,如果我使用file_put_contents(),它与捕获的图像或文件相同。

举个图像的例子,谷歌网站给了我一个25K的图像,但上传量是17.2K。一个55K的pdf以40.7K的速度上传。另一个pdf是1.5MB,但上传速度是1.1MB。当我将文件与数据库blob进行比较时,数据库中的blob在文件底部缺少内容。

大小和内容在文件之间并不一致,但对于相同的捕获是一致的。

有人有什么想法吗?

更新我已经把它缩小到准备好的声明和上传之间发生的事情。

此外,当使用准备好的语句时,PDO和MySQLI都会发生这种情况。第一个假设是某个地方的字符集编码不正确,但所有内容都定义为UTF8(数据库、表、PDO连接、配置文件)。

发现问题后,这篇文章现在看起来很傻,但万一将来有人遇到这个问题。。。

旧版本的PHPMyAdmin出现错误,无法正确显示或下载blob列中的数据。