Hi all,
First off I know that my English is not good. For this reason I wrote longer code as example than text. I'm trying to solve the problem, but something go wrong. I don't know what's wrong with my code?
I read http://dev.mysql.com/doc/refman/5.1/en/charset-applications.html and http://dev.mysql.com/doc/refman/5.1/en/charset-connection.html. I included this <meta> tag within my <head> element. My database will use default character set and collation for data storage. Tables created in the database will use utf8 and utf8_polish_ci by default for any character columns. I typed into my table word 'Gżegż贸łka'. I conected to database MySQL. My application configure their connection to the server each time they connect. This is done by executing a "SET NAMES utf-8" statement after connecting. After all I created simple query to the database "query("select kolumna from tabela")". The result is following:
1. window GTK shows 'Gżegż贸łka'
2. browser Mozilla shows this ugly text 'G�eg���ka'.
How to solve the problem?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
<head>
<title>strona testowa</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<?php
/*
---------------------------------------------------------------------------------
My database and table
---------------------------------------------------------------------------------
CREATE DATABASE baza_utf DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_polish_ci;
use baza_utf;
CREATE TABLE tabela (kolumna VARCHAR(20));
INSERT INTO tabela (kolumna) values ('Gżegż贸łka');
---------------------------------------------------------------------------------
*/
$mysqli = new mysqli("127.0.0.1", "user", "password", "baza_utf");
//check connection
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$mysqli->query("SET NAMES utf-8");
if ($result = $mysqli->query("select kolumna from tabela")) {
while ($row = $result->fetch_row()) {
echo $row[0];
}
$result->close();
}
$mysqli->close();
?>
</body>
</html>