问题
When I insert Persian data to database, data will save like this: †Ø¯Ø± 50 لیتری
But when I read data from database and echo it on the web, they are Ok.
I need to read data in my database directly. what is your solution?
Mysql setting:
Server connection collation: UTF8_general_ci
Html file charset is utf8.
回答1:
I had a same issue,this code: mysqli_set_charset($con, "utf8");
solved my problem!
回答2:
you should use this code
$yourConnection->set_charset("utf8");
for example
function insertUser($inUN,$inP,$inFN,$inLN,$inE,$inD)
{
$servername="localhost";
$username="mnr";
$password="milad1373";
$databacename="mnr01";
$conn = new mysqli($servername, $username, $password, $databacename);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$conn->set_charset("utf8");
$sql = "INSERT INTO chuser (username, passWord, fname,lname,email,date)
VALUES ('$inUN', '$inP','$inFN','$inLN', '$inE','$inD')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
i had this problem but it resolved by this code and for more information go to this link
回答3:
Make sure you have executed
SET character_set_results=utf8
SET NAMES 'utf8'
before you send any INSERT
command.
Have a look at this question for more information. I think it may help;
- UTF8 All The Way Through
回答4:
solved:
in connection
<?php
$dbLink = mysql_connect($argHost, $argUsername, $argPassword);
mysql_query("SET character_set_results=utf8", $dbLink);
mb_language('uni');
mb_internal_encoding('UTF-8');
mysql_select_db($argDB, $dbLink);
mysql_query("set names 'utf8'",$dbLink);
?>
source: PHP mysql charset utf8 problems
回答5:
You should change your collation to utf8_unicode_ci
in your phpmyadmin:
- Go you your localhost/phpmyadmin
- Select your database
- Next to your database there's an small icon click on that
- Click on change
- Change your collation to
utf8_unicode_ci
. - Insert this code to your php file.
if (!$connection->set_charset("utf8")) { printf("Error loading character set utf8: %s\n", $mysqli->error); exit(); } else { printf("Current character set: %s\n", $connection->character_set_name()); }
来源:https://stackoverflow.com/questions/20519496/persian-characters-issue-in-mysql-database