Persian character's issue in mysql database

独自空忆成欢 提交于 2019-12-23 16:34:19

问题


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:

  1. Go you your localhost/phpmyadmin
  2. Select your database
  3. Next to your database there's an small icon click on that
  4. Click on change
  5. Change your collation to utf8_unicode_ci.
  6. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!