pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

      <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="3b2mzc3" 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="t27wknh" 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="ix82w3q" id='ILXlJ'><tfoot id='ILXlJ'></tfoot><dl id='ILXlJ'><fieldset id='ILXlJ'></fieldset></dl></div>
                    • <bdo id='ILXlJ'></bdo><ul id='ILXlJ'></ul>

                            主站蜘蛛池模板: 太阳能发电系统-太阳能逆变器,控制器-河北沐天太阳能科技首页 | 磁力反应釜,高压釜,实验室反应釜,高温高压反应釜-威海自控反应釜有限公司 | 杭州公司变更法人-代理记账收费价格-公司注销代办_杭州福道财务管理咨询有限公司 | 不锈钢轴流风机,不锈钢电机-许昌光维防爆电机有限公司(原许昌光维特种电机技术有限公司) | 深圳公司注册-工商注册代理-注册公司流程和费用_护航财税 | 亮点云建站-网站建设制作平台 | 广域铭岛Geega(际嘉)工业互联网平台-以数字科技引领行业跃迁 | 山东成考网-山东成人高考网| 卷筒电缆-拖链电缆-特种柔性扁平电缆定制厂家「上海缆胜」 | 河南档案架,档案密集架,手动密集架,河南密集架批发/报价 | 深圳标识制作公司-标识标牌厂家-深圳广告标识制作-玟璟广告-深圳市玟璟广告有限公司 | 商标转让-购买商标专业|放心的商标交易网-蜀易标商标网 | 呼末二氧化碳|ETCO2模块采样管_气体干燥管_气体过滤器-湖南纳雄医疗器械有限公司 | 超细粉碎机|超微气流磨|气流分级机|粉体改性设备|超微粉碎设备-山东埃尔派粉碎机厂家 | 西安展台设计搭建_西安活动策划公司_西安会议会场布置_西安展厅设计西安旭阳展览展示 | 沈阳缠绕膜价格_沈阳拉伸膜厂家_沈阳缠绕膜厂家直销 | 辊道窑炉,辊道窑炉厂家-山东艾希尔| 天津货架厂_穿梭车货架_重型仓储货架_阁楼货架定制-天津钢力仓储货架生产厂家_天津钢力智能仓储装备 | 全自动端子机|刺破式端子压接机|全自动双头沾锡机|全自动插胶壳端子机-东莞市傅氏兄弟机械设备有限公司 | 湖南印刷厂|长沙印刷公司|画册印刷|挂历印刷|台历印刷|杂志印刷-乐成印刷 | 水上浮桥-游艇码头-浮动码头-游船码头-码瑞纳游艇码头工程 | 艺术涂料_进口艺术涂料_艺术涂料加盟_艺术涂料十大品牌 -英国蒙太奇艺术涂料 | 非甲烷总烃分析仪|环控百科| RO反渗透设备_厂家_价格_河南郑州江宇环保科技有限公司 | 哲力实业_专注汽车涂料汽车漆研发生产_汽车漆|修补油漆品牌厂家 长沙一级消防工程公司_智能化弱电_机电安装_亮化工程专业施工承包_湖南公共安全工程有限公司 | 高速混合机_锂电混合机_VC高效混合机-无锡鑫海干燥粉体设备有限公司 | 智慧养老_居家养老_社区养老_杰佳通| 食品机械专用传感器-落料放大器-低价接近开关-菲德自控技术(天津)有限公司 | hc22_hc22价格_hc22哈氏合金—东锜特殊钢 | 矿用履带式平板车|探水钻机|气动架柱式钻机|架柱式液压回转钻机|履带式钻机-启睿探水钻机厂家 | 齿轮减速马达一体式_蜗轮蜗杆减速机配电机-德国BOSERL齿轮减速电动机生产厂家 | 辐射色度计-字符亮度测试-反射式膜厚仪-苏州瑞格谱光电科技有限公司 | 工业铝型材生产厂家_铝合金型材配件批发精加工定制厂商 - 上海岐易铝业 | 卓能JOINTLEAN端子连接器厂家-专业提供PCB接线端子|轨道式端子|重载连接器|欧式连接器等电气连接产品和服务 | 板框压滤机-隔膜压滤机-厢式压滤机生产厂家-禹州市君工机械设备有限公司 | atcc网站,sigma试剂价格,肿瘤细胞现货,人结肠癌细胞株购买-南京科佰生物 | 绿萝净除甲醛|深圳除甲醛公司|测甲醛怎么收费|培训机构|电影院|办公室|车内|室内除甲醛案例|原理|方法|价格立马咨询 | 在线钠离子分析仪-硅酸根离子浓度测定仪-油液水分测定仪价格-北京时代新维测控设备有限公司 | 减速机电机一体机_带电机减速器一套_德国BOSERL电动机与减速箱生产厂家 | 联系我们-腾龙公司上分客服微信19116098882 | 焊锡丝|焊锡条|无铅锡条|无铅锡丝|无铅焊锡线|低温锡膏-深圳市川崎锡业科技有限公司 |