mysql 插入表情報錯,mysql插入表情報

來源:互聯網
上載者:User

mysql 插入表情報錯,mysql插入表情報

今天做的了個擷取粉絲的功能,發現將暱稱插入資料庫報錯.長度肯定是夠的

Incorrect string value: '\xF0\x9F\x98\x84\xF0\x9F

找了點資料發現UTF-8編碼有可能是兩個、三個、四個位元組。Emoji表情或者某些特殊字元是4個位元組,而Mysql的utf8編碼最多3個位元組,所以資料插不進去。

網上解決方案都是

修改mysql配置

1.在mysql的安裝目錄下找到my.ini,作如下修改:
[mysqld]
character-set-server=utf8mb4
[mysql]
default-character-set=utf8mb4

2 重啟

net stop mysql
net start mysql

3 修改表

 ALTER TABLE 表名 CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;


我只做了第三步就解決我的問題了,現將其記錄下來


mysql的插入語句錯誤

mysql_select_db($dbname);

<?php
require('conn.inc.php');
$dbname="mydb"; //
mysql_select_db($dbname); //選擇資料庫,這個必須執行
$name="soundbbg";
$password=md5("0123456");

$sql="INSERT INTO admin ('$name') VALUES ('$password')";
//sql語句,如果是mysql,那麼你把欄位名用反引號括起來,而不是單引號,`$name`
$result=mysql_query($sql);

if($result)
{
echo"success!";
}
else
{
echo"wrong!";
}
echo"$sql"
?>
 
mysql中執行插入語句時報錯

這個是"mysql.proc"系統資料表有問題

你得用mysql_upgrade去處理下看看是否能解決.

找出你的mysql的參數basedir(下面假設是xxx--包括路徑名),然後執行下面的:

mysql_upgrade -uroot -p密碼 --basedir=xxx
 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.