php - Is a BLOB converted using the current/default charset in MySQL? -
i have table blob field. the charset of table latin1. i connect db , "set character set utf8". then save binary info field. then retrieve data, , it's not saved (corrupt).
the code:
<?php $pdo = new \pdo("mysql:host=127.0.0.1;dbname=***", '***', '***'); $pdo->exec('set character set utf8'); $sql = "insert pdo_blob (the_blob) values(:the_blob)"; $insertstm = $pdo->prepare($sql); $blob = (binary) file_get_contents('/home/***/test.pdf'); $insertstm->bindparam(":the_blob", $blob, \pdo::param_lob); $insertstm->execute(); $selectstm = $pdo->prepare("select the_blob pdo_blob order id desc limit 1"); $selectstm->execute(); $savedblob = null; $selectstm->bindcolumn(1, $savedblob, \pdo::param_lob); $selectstm->fetch(); echo 'equal: ' . ((int) ($blob == $savedblob));
good reply @mvp!
but when web app utf-8 , database encoding latin1
, have to set character_set_client
, character_set_results
.
when utilize set character set utf8
, got described problem blobs.
but when utilize set names utf8
instead works!
php mysql perl utf-8 pdo
No comments:
Post a Comment