国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

mysql如何存儲emoji表情

2024-07-24 12:39:29
字體:
來源:轉載
供稿:網友

在mysql中如何存儲emoji表情,如果mysql是utf-8編碼,存入表情符出錯我們如何解決,下面我們來介紹一下.

utf8的數據庫,存入表情符,會出錯,代碼如下:

Incorrect string value: '/xF0/x9F/x98/x84/xF0/x9F...' for column 'content'

錯誤的解決辦法:

  1. 4 byte Unicode characters aren't yet widely used, so not every application out there fully supports them. MySQL 5.5 works fine with 4 byte characters when properly configured – check if your other components can work with them as well. 
  2.  
  3. Here's a few other things to check out: 
  4.  
  5. Make sure all your tables' default character sets and text fields are converted to utf8mb4, in addition to setting the client & server character sets, e.g. ALTER TABLE mytable charset=utf8mb4, MODIFY COLUMN textfield1 VARCHAR(255) CHARACTER SET utf8mb4,MODIFY COLUMN textfield2 VARCHAR(255) CHARACTER SET utf8mb4; and so on. 
  6.  
  7. If your data is already in the utf8 character set, it should convert to utf8mb4 in place without any problems. As always, back up your data before trying! 
  8.  
  9. Also make sure your app layer sets its database connections' character set to utf8mb4. Double-check this is actually happening – if you're running an older version of your chosen framework's mysql client library, it may not have been compiled with utf8mb4 support and it won't set the charset properly. If not, you may have to update it or compile it yourself.  //開源軟件:Vevb.com 
  10.  
  11. When viewing your data through the mysql client, make sure you're on a machine that can display emoji, and run a SET NAMES utf8mb4 before running any queries. 
  12.  
  13. Once every level of your application can support the new characters, you should be able to use them without any corruption. 

總結就是:表結構改為支持4字節的unicode,數據庫連接也用這個字符集哦,證明是可行的,如果別的地方不支持,可以考慮去掉這些字符:

  1. Since 4-byte UTF-8 sequences always start with the bytes 0xF0-0xF7, the following should work: 
  2.  
  3. $str = preg_replace('/[/xF0-/xF7].../s'''$str); 
  4. Alternatively, you could use preg_replace in UTF-8 mode but this will probably be slower: 
  5.  
  6. $str = preg_replace('/[/x{10000}-/x{10FFFF}]/u'''$str); 
  7. This works because 4-byte UTF-8 sequences are used for code points in the supplementary Unicode planes starting from 0x10000.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 海口市| 开远市| 鞍山市| 方正县| 泗阳县| 时尚| 工布江达县| 同德县| 长乐市| 浪卡子县| 嘉义市| 库伦旗| 东阳市| 邢台县| 乌兰察布市| 桂东县| 精河县| 稻城县| 南江县| 许昌市| 连云港市| 青田县| 龙口市| 苏尼特右旗| 繁峙县| 凌海市| 延安市| 溧阳市| 临汾市| 绥芬河市| 聂拉木县| 库伦旗| 宁武县| 平乡县| 游戏| 宣汉县| 公安县| 高碑店市| 子洲县| 乳山市| 阿荣旗|