我有一个 mysql 表成员。成员名称具有阿拉伯名称。mname 排序规则设置为utf8_general_ci
.
当用户输入阿拉伯名称时,它在 db 表中存储为其他一些字符。但是当我在网站中检索并显示它时,它会正确显示为阿拉伯语文本。为什么它不在数据库表中存储为阿拉伯文本?
我试过这个,但只有我得到问号,没有阿拉伯文字......
1- MySQL charset: UTF-8 Unicode (utf8)
2- MySQL connection collation: utf8_general_ci
3- your database and table collations are set to: utf8_general_ci or utf8_unicode_ci
Then, add this code in your php script when you connect to db:
mysql_query("SET NAMES 'utf8'"); mysql_query('SET CHARACTER SET utf8');
php代码:
使用简单的 php。
$mname = $_POST['mname'];
$email = $_POST['email'];
$password = $_POST['password'];
$gender = $_POST['gender'];
$age = $_POST['age'];
$city = $_POST['city'];
$country = $_POST['country'];
$query="insert into member (mname, email, password, gender, age, city, country) values ('$mname','$email','$password', '$gender', '$age','$city','$country')";
mysql_query("SET NAMES 'utf8'");
mysql_query('SET CHARACTER SET utf8');
mysql_query($query);