久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <bdo id='qsC5k'></bdo><ul id='qsC5k'></ul>

  • <tfoot id='qsC5k'></tfoot>
    <i id='qsC5k'><tr id='qsC5k'><dt id='qsC5k'><q id='qsC5k'><span id='qsC5k'><b id='qsC5k'><form id='qsC5k'><ins id='qsC5k'></ins><ul id='qsC5k'></ul><sub id='qsC5k'></sub></form><legend id='qsC5k'></legend><bdo id='qsC5k'><pre id='qsC5k'><center id='qsC5k'></center></pre></bdo></b><th id='qsC5k'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='qsC5k'><tfoot id='qsC5k'></tfoot><dl id='qsC5k'><fieldset id='qsC5k'></fieldset></dl></div>

        <small id='qsC5k'></small><noframes id='qsC5k'>

        <legend id='qsC5k'><style id='qsC5k'><dir id='qsC5k'><q id='qsC5k'></q></dir></style></legend>

        PHP/PDO/MySQL:插入 MEDIUMBLOB 存儲壞數據

        PHP/PDO/MySQL: inserting into MEDIUMBLOB stores bad data(PHP/PDO/MySQL:插入 MEDIUMBLOB 存儲壞數據)
      1. <tfoot id='nEr98'></tfoot>
      2. <legend id='nEr98'><style id='nEr98'><dir id='nEr98'><q id='nEr98'></q></dir></style></legend>

            1. <i id='nEr98'><tr id='nEr98'><dt id='nEr98'><q id='nEr98'><span id='nEr98'><b id='nEr98'><form id='nEr98'><ins id='nEr98'></ins><ul id='nEr98'></ul><sub id='nEr98'></sub></form><legend id='nEr98'></legend><bdo id='nEr98'><pre id='nEr98'><center id='nEr98'></center></pre></bdo></b><th id='nEr98'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='nEr98'><tfoot id='nEr98'></tfoot><dl id='nEr98'><fieldset id='nEr98'></fieldset></dl></div>

                  <bdo id='nEr98'></bdo><ul id='nEr98'></ul>

                  <small id='nEr98'></small><noframes id='nEr98'>

                    <tbody id='nEr98'></tbody>
                  本文介紹了PHP/PDO/MySQL:插入 MEDIUMBLOB 存儲壞數據的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個簡單的 PHP Web 應用程序,它通過文件上傳接受圖標圖像并將它們存儲在 MEDIUMBLOB 列中.

                  I have a simple PHP web app that accepts icon images via file upload and stores them in a MEDIUMBLOB column.

                  在我的機器 (Windows) 和兩臺 Linux 服務器上,這工作正常.在第三臺 Linux 服務器上,插入的圖像已損壞:在 SELECT 后無法讀取,并且 MySQL length() 函數報告的列數據長度比上傳文件的大小大 40% 左右.

                  On my machine (Windows) plus two Linux servers, this works fine. On a third Linux server, the inserted image is corrupted: unreadable after a SELECT, and the length of the column data as reported by the MySQL length() function is about 40% larger than the size of the uploaded file.

                  (每個服務器連接到一個單獨的 MySQL 實例.)

                  (Each server connects to a separate instance of MySQL.)

                  當然,這讓我想到了編碼和字符集問題.BLOB 列沒有關聯的字符集,因此似乎最有可能的罪魁禍首是 PDO 及其對該列的參數值的解釋.

                  Of course, this leads me to think about encoding and character set issues. BLOB columns have no associated charsets, so it seems like the most likely culprit is PDO and its interpretation of the parameter value for that column.

                  • 我嘗試將 bindValue 與 PDO::PARAM_LOB 結合使用,但沒有效果.
                  • 我已經確認服務器上正確接收了圖像(即在上傳后讀取它們沒有問題),因此這絕對是 DB/PDO 問題.
                  • 我已經搜索了服務器之間明顯的配置差??異,但我不是 PHP 配置方面的專家,所以我可能遺漏了一些東西.

                  插入代碼大致如下:

                  $imagedata = file_get_contents($_FILES["icon"]["tmp_name"]);
                  $stmt = $pdo->prepare('insert into foo (theimage) values (:theimage)');
                  $stmt->bindValue(':theimage', $imagedata, PDO::PARAM_LOB);
                  $stmt->execute();
                  

                  任何幫助將不勝感激.

                  UPDATE:有問題的服務器上的默認 MySQL 字符集是 utf8;其他人是latin1.

                  UPDATE: The default MySQL charset on the problematic server is utf8; it's latin1 on the others.

                  問題通過添加PDO::MYSQL_ATTR_INIT_COMMAND =>SET NAMES latin1 COLLATE latin1_general_ci" 到 PDO 構造函數.

                  The problem is "solved" by adding PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES latin1 COLLATE latin1_general_ci" to the PDO constructor.

                  這對我來說似乎一個錯誤糟糕的設計:為什么連接的字符集會對二進制列的數據產生任何影響,特別是當它被識別為用 PARAM_LOB 二進制到 PDO 本身?

                  This seems like a bug poor design to me: why should the charset of the connection have any effect on data for a binary column, particularly when it's been identified as binary to PDO itself with PARAM_LOB?

                  請注意,數據庫表在所有情況下都定義為 latin1:只有服務器的默認字符集不一致.

                  Note that the DB tables are defined as latin1 in all cases: it's only the servers' default charsets that are inconsistent.

                  推薦答案

                  這對我來說似乎是一個錯誤:為什么連接的字符集會對二進制列的數據產生任何影響,尤其是當它被識別為 PDO 本身的二進制數據時,PARAM_LOB?

                  This seems like a bug to me: why should the charset of the connection have any effect on data for a binary column, particularly when it's been identified as binary to PDO itself with PARAM_LOB?

                  我不認為這一定是一個錯誤.我可以想象,每當客戶端與服務器交談并說以下命令是 UTF-8 并且服務器需要它是 Latin-1 時,那么查詢可能會在解析和執行之前重新編碼.所以這是數據傳輸的編碼問題.由于整個查詢優先解析會受到這種重新編碼的影響,BLOB 列的二進制數據也會發生變化.

                  I do not think that this must be a bug. I can imagine that whenever the client talks with the server and says that the following command is in UTF-8 and the server needs it in Latin-1, then the query might get re-encoded prior parsing and execution. So this is an encoding issue for the transportation of the data. As the whole query prior parsing will get influenced by this re-encoding, the binary data for the BLOB column will get changed as well.

                  來自 Mysql 手冊:

                  服務器收到語句后應該翻譯成什么字符集?

                  為此,服務器使用 character_set_connection 和 collat??ion_connection 系統變量.它將客戶端發送的語句從 character_set_client 轉換為 character_set_connection(具有介紹人的字符串文字除外,例如 _latin1 或 _utf8).collat??ion_connection 對于文字字符串的比較很重要.對于字符串與列值的比較,collat??ion_connection 無關緊要,因為列有自己的排序規則,具有更高的排序規則優先級.

                  For this, the server uses the character_set_connection and collation_connection system variables. It converts statements sent by the client from character_set_client to character_set_connection (except for string literals that have an introducer such as _latin1 or _utf8). collation_connection is important for comparisons of literal strings. For comparisons of strings with column values, collation_connection does not matter because columns have their own collation, which has a higher collation precedence.

                  或者在返回的路上:來自商店的 Latin1 數據將被轉換為 UTF-8,因為客戶端告訴服務器它更喜歡使用 UTF-8 進行傳輸.

                  Or on the way back: Latin1 data from the store will get converted into UTF-8 because the client told the server that it prefers UTF-8 for the transportation.

                  您命名的 PDO 本身的標識符看起來完全不同:

                  The identifier for PDO itself you name looks like being something entirely different:

                  PDO::PARAM_LOB 告訴 PDO 將數據映射為流,以便您可以使用 PHP Streams API 對其進行操作.(參考)

                  PDO::PARAM_LOB tells PDO to map the data as a stream, so that you can manipulate it using the PHP Streams API. (Ref)

                  我不是 MySQL 專家,但我會這樣解釋.客戶端和服務器需要協商他們使用的字符集,我認為他們這樣做是有原因的.

                  I'm no MySQL expert but I would explain it this way. Client and server need to negotiate which charsets they are using and I assume they do this for a reason.

                  這篇關于PHP/PDO/MySQL:插入 MEDIUMBLOB 存儲壞數據的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環)
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數)
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“localhost的訪問被拒絕)

                    <tbody id='ILXlJ'></tbody>
                • <legend id='ILXlJ'><style id='ILXlJ'><dir id='ILXlJ'><q id='ILXlJ'></q></dir></style></legend>

                  • <tfoot id='ILXlJ'></tfoot>

                    <small id='ILXlJ'></small><noframes id='ILXlJ'>

                    <i id='ILXlJ'><tr id='ILXlJ'><dt id='ILXlJ'><q id='ILXlJ'><span id='ILXlJ'><b id='ILXlJ'><form id='ILXlJ'><ins id='ILXlJ'></ins><ul id='ILXlJ'></ul><sub id='ILXlJ'></sub></form><legend id='ILXlJ'></legend><bdo id='ILXlJ'><pre id='ILXlJ'><center id='ILXlJ'></center></pre></bdo></b><th id='ILXlJ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ILXlJ'><tfoot id='ILXlJ'></tfoot><dl id='ILXlJ'><fieldset id='ILXlJ'></fieldset></dl></div>
                    • <bdo id='ILXlJ'></bdo><ul id='ILXlJ'></ul>

                            主站蜘蛛池模板: 日韩精品无码一区二区三区 | 日日夜夜天天 | 国产精品日女人 | 国产一级电影在线 | 天堂一区 | 国产高清一二三区 | 天堂中文在线观看 | 91视频在线 | 国产中文字幕网 | 精品国产一区二区三区av片 | 久久国产成人 | 亚洲精品视频免费 | 国产三级在线观看播放 | 日韩1区| 国产视频二区在线观看 | 综合久 | 久久综合九色综合欧美狠狠 | 久久成人一区 | 可以看黄的视频 | 精品九九九 | 亚洲精品视频久久 | 黄色片在线 | 国产婷婷色一区二区三区 | www.国产日本| 龙珠z在线观看 | 久久成 | 欧美一区久久 | 国产日韩欧美一区二区 | 亚洲码欧美码一区二区三区 | 国产精品欧美一区二区三区 | 久久国内精品 | 欧美一区二 | 久久久久久国产精品mv | www.久久影视 | 欧美性生活网 | 国产女人精品视频 | 国产精品久久久久久久久久久久冷 | 久久久久久国产精品免费免费狐狸 | 国产人成精品一区二区三 | 亚洲国产精品99久久久久久久久 | 欧美精品一区二区三区蜜桃视频 |