Frage

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.

War es hilfreich?

Lösung 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

Andere Tipps

I had a same issue,this code: mysqli_set_charset($con, "utf8"); solved my problem!

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

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;

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());
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top