我将一个大文件(36.5MB zip存档)存储到mysql longblob字段中。
有些文件我无法通过PHP(pdo)上的select语句获取相同的结果。
我使用PHP 7.0.15和MySQL 5.6.35。
这是代码。
$original_data = base64_encode(file_get_contents($file_path));
$nickname = 'nickname';
/** @var PDO $pdo */
$pdo = DB::instance()->connection();
$stmt = $pdo->prepare('update dump_data set data=? where nickname=?');
$stmt->execute([$original_data, $nickname]);
$stmt = $pdo->prepare('select data from dump_data where nickname=?');
$stmt->execute([$nickname]);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
$fetched_data = $result['data'];
echo "original_data ===\n";
var_dump($original_data);
echo "fetched_data ===\n";
var_dump($fetched_data);
echo "compare ===\n";
var_dump($original_data == $fetched_data);
而且,结果就是这样。
original_data ===
string(48701976) "UEsDBBQAAAAIAFVcSkqWW9ZhqhcAAKoaAAAZABwAa2luam8tdS8wMF9maWxlX2xpc3QueGxzeFVUCQADwiadWMImnVh1eAsAAQT0AQAABPQBAACNWAVUVO26HinpZpAGBWQI6S4Zuocu6Q4ZBCkB6ZJGSmDolhq6kRCkUxhCWhpJaeXi/5+7PHL+c9fde+39rW+v9Txr7be+930gisgoxAAAAB2QYKCgIBsvVaV7DwA4QAEAiG6/GkhCHV9aOr401vR0snQxfOLx3KEsQVmliwM/+Cz94RGQwVGPNijVTcIUI5HpPsdpHnwbkWR96e7FaIuFHv70s6OZ9KnX4rnn7pjFXIMDDsbzg/wHQOQ4/+kO3Xamj3PXoHYisvgjmcalbGLhp5xkxlHrzegpcIQ5yC7Hg51hm5w8WDpsybMAs1itu92WLndcsRbgyf1gXoFKxL8wXR+Pk7qVQ1wPeUaJ4ZU2jvnalLwZP8I3FPUqfNeU3WEmH8Ip9J7kxbLz3hCe"...
fetched_data ===
string(48701976) "UEsDBBQAAAAIAFVcSkqWW9ZhqhcAAKoaAAAZABwAa2luam8tdS8wMF9maWxlX2xpc3QueGxzeFVUCQADwiadWMImnVh1eAsAAQT0AQAABPQBAACNWAVUVO26HinpZpAGBWQI6S4Zuocu6Q4ZBCkB6ZJGSmDolhq6kRCkUxhCWhpJaeXi/5+7PHL+c9fde+39rW+v9Txr7be+930gisgoxAAAAB2QYKCgIBsvVaV7DwA4QAEAiG6/GkhCHV9aOr401vR0snQxfOLx3KEsQVmliwM/+Cz94RGQwVGPNijVTcIUI5HpPsdpHnwbkWR96e7FaIuFHv70s6OZ9KnX4rnn7pjFXIMDDsbzg/wHQOQ4/+kO3Xamj3PXoHYisvgjmcalbGLhp5xkxlHrzegpcIQ5yC7Hg51hm5w8WDpsybMAs1itu92WLndcsRbgyf1gXoFKxL8wXR+Pk7qVQ1wPeUaJ4ZU2jvnalLwZP8I3FPUqfNeU3WEmH8Ip9J7kxbLz3hCe"...
compare ===
bool(false)
对于转储数据被剪切,它似乎是相同的,但获取的数据实际上与原始数据不同。
当我将较小的数据保存到字段中时,我可以成功地获得正确的结果。
original_data ===
string(19) "aaaaaaaaaaaaaaaaaaa"
fetched_data ===
string(19) "aaaaaaaaaaaaaaaaaaa"
compare ===
bool(true)
为什么获取的值与我刚刚更新的值不同? 有没有人遇到同样的问题?