View Full Version : Issue with UTF8 encoding

05-12-2010, 04:44 AM
Hi !
I am using Quercus with Glassfish and Mysql.

Although everything is set up to support UTF8 (see details below), when i try to retrieve some data from MySql using php, the charset is still Latin1 ... anybody has an idea before i go crazy ? :rolleyes:

My php script :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php header("Content-type: text/html; charset=utf-8");?>
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-type" value="text/html; charset=utf-8">


/* connection to server */
$host = 'localhost';
$user = 'root';
$pass = 'f14tomca';
$bdd = 'test';

/* connection to MySQL database */
$link = mysql_connect($host,$user,$pass) or die('Impossible to connect to server');
mysql_select_db($bdd) or die('Connected to server but fail to connect to database');
mysql_query("SET NAMES 'utf8' COLLATE 'utf8_general_ci'", $link);
mysql_query('SET CHARACTER_SET utf8');
echo "encoding = ".mysql_client_encoding($link);
echo "<br />";

$reqMain = "SELECT id, comment FROM test";
$reqResultMain = mysql_db_query($bdd,$reqMain);
while ($valMain = mysql_fetch_array($reqResultMain)) {
$id = $valMain["id"];
$comment = $valMain["comment"];
echo " record : $id - $comment - decode = ";
echo utf8_decode($comment)

$req = "SELECT CHARSET(CONVERT('".$comment."' USING utf8));";

$req = "SELECT CHARSET('".$comment."') AS ch";
$reqResult = mysql_db_query($bdd,$req);
while ($val = mysql_fetch_array($reqResult)) {
$ch = $val["ch"];
echo " charset = ".$ch;
echo "<br />";



My Glassfish sun-web.xml file :
<parameter-encoding default-charset="UTF-8" />

My Quercus web.xml file :

MySQL my.ini file :

On top of that, the Table 'test' an database 'test' have both charset UTF8 and Collation utf8_general_ci

I also checked the php file containing my script is using UTF8 encoding....

05-12-2010, 05:39 PM
Hi Blackdalhia,

The problem may well be in the MySQL Connector/J. We've had numerous problems in the past with it and encodings. We're considering writing a replacement driver to address the issues, but that won't happen for some time. If you have control over what database to use, you might try another one, at least just for testing to see if the driver is indeed the problem.


05-13-2010, 12:06 AM
mmm change database ? you mean different from Mysql ? which one would you suggest ?

I m afraid I'm going to move to an apache solution rather than Quercus .... too bad i really like this solution.