my table char set is utf8 and it's collation is utf8.now i have this code:
$mysqli = new mysqli("localhost", "root", "", "Amoozeshgah"); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); } if (!$mysqli->set_charset("utf8")) { printf("Error loading character set utf8: %s\n", $mysqli->error); } else { printf("Current character set: %s\n", $mysqli->character_set_name()); } mysql_set_charset('utf8'); if ($stmt = $mysqli->prepare("SELECT About_Title FROM Tbl_About WHERE About_Id=?")) { $city = 8; /* bind parameters for markers */ $stmt->bind_param("s", $city); /* execute query */ $stmt->execute(); /* bind result variables */ $result = $stmt->get_result(); /* fetch value */ while ($myrow = $result->fetch_assoc()) { // use your $myrow array as you would with any other fetch printf("%s is in district %s\n", $city, $myrow['About_Title']); print("shod"); }
but out put is:
Current character set: utf8 8 is in district نتمنتشس shod
what can i do? Edit: i replaced:
if (!$mysqli->set_charset("utf8")) { printf("Error loading character set utf8: %s\n", $mysqli->error); } else { printf("Current character set: %s\n", $mysqli->character_set_name()); } mysql_set_charset('utf8');
with
$mysqli->set_charset("utf8")
but no difference.
The difference between utf8 and utf8mb4 is that the former can only store 3 byte characters, while the latter can store 4 byte characters. In Unicode terms, utf8 can only store characters in the Basic Multilingual Plane, while utf8mb4 can store any Unicode character.
utf-8 can store only 1, 2 or 3 bytes characters, while utf8mb4 can store 4 bytes characters as well. utf-8 is a subset of characters given by utf8mb4 .
Definition and Usage. The utf8_encode() function encodes an ISO-8859-1 string to UTF-8. Unicode is a universal standard, and has been developed to describe all possible characters of all languages plus a lot of symbols with one unique number for each character/symbol.
Please replace mysql_set_charset('utf8');
to $mysqli->set_charset("utf8")
:-)
or mysqli_set_charset($this->mysqli,"utf8"); mysqli_set_charset($conn,"utf8");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With