Reputation: 183
I've got a database with utf8_general_ci encoding, but when I fetch the data with php to the page it shows "????", what's wrong?
<?php
$query1 = "SELECT name FROM `kotegorii`";
$result1 = mysql_query($query1) or die(mysql_error());
echo "<h3>Категориялар</h3>";
while ($row = mysql_fetch_array($result1)) {
echo $row['name']."<br>";
}
?>
the code is written using the UTF-8 encoding also..
Upvotes: 0
Views: 11373
Reputation: 111389
You have to set the MySQL connection encoding to UTF-8 right after connecting to the database with mysql_set_charset:
mysql_set_charset('utf8');
The server uses the connection encoding to send information to the client, no matter how the text is encoded in the storage. The connection encoding is latin1
by default on many installations.
Also, you shouldn't use the old mysql
API in new code; it is deprecated and will be removed from PHP in some future version.
Upvotes: 7
Reputation: 365
I don't know how your data looks but have you tried utf8_decode
utf8_encode
on $row['name']
?
Upvotes: 0
Reputation: 3200
You should set page encoding too.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<!-- and so on -->
Upvotes: 0