2017-05-28 55 views
0

我一直在閱讀文檔和搜索google-net試圖找出如何構建mysql的select查詢,該查詢返回varchar字段中的雙引號。mysql選擇替換雙引號和#標籤

我發現的一切都表示不要在第一位插入引號而不會逃脫它們。同意100%...但我已經收到了其他人的數據庫。他們使用MySQL Workbench創建它...允許他們在varchar字段中輸入雙引號值。我怎麼得到雙重報價? mysql客戶端(命令行)和mysqli(php)都將雙引號轉換爲散列標籤。

我可以轉儲數據庫,通過它手動替換所有引號,然後重新導入。但是這隻有在我收到這個數據庫的下一個交付之前纔有效。

我在這裏錯過了什麼?

(我嘗試添加屏幕截圖,但Imagur似乎並不希望立即對它們進行處理)......所以這裏是我所看到的複製/粘貼:

在MySQL工作臺(只「價值」 字段):

If you would like to keep your responses anonymous, you may do so. Simply click on the 」anonymous」 checkbox above each 」Feedback」 block. When you submit your survey, you will be sent a link, by email, to revisit/modify your responses. Hold onto that email as that will be the only mechanism for associating you with your anonymous responses. 

從MySQL客戶端:

mysql> select * from survey_labels where item_id=149; 
+---------+------+-------+--------+------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
| item_id | type | level | italic | bold | size | value                                                                                     | 
+---------+------+-------+--------+------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
|  149 | text |  2 |  0 | 0 | NULL | If you would like to keep your responses anonymous, you may do so. Simply click on the #anonymous# checkbox above each #Feedback# block. When you submit your survey, you will be sent a link, by email, to revisit/modify your responses. Hold onto that email as that will be the only mechanism for associating you with your anonymous responses. | 
+---------+------+-------+--------+------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
1 row in set (0.09 sec) 

回答

1

我會用PHPs function htmlspecialchars()這些特殊字符轉換爲html-codes

但是對於你的問題:找出你的Workbench使用的是哪種編碼,並讓你的PHP和你的mysql客戶端使用相同的編碼。您可以在工作臺的創建腳本中和客戶端的選項中找到它。

如果實際上有雙引號,請檢查該腳本。

如果這導致什麼都不做,只是將數據庫中的值更改爲",因爲您將使用該表的99%用於前端輸出,並且只有1%是通過工作臺訪問的。

+0

你弄明白了這個問題。編碼中存在不匹配。他們的表使用utf8_unicode_ui。我加載數據的表格是latin1_general_ui。我檢查了他們發送給我的表創建SQL,並且它對編碼保持沉默......所以我猜我有一些默認情況,假定是後者。 非常感謝! – MikeMayer67