I'm a Debian Lenny user. I have an Apache-php5.2.8-mysql5.1.30 webserver on my local home machine. The website I have developped uses UTF-8 as its page encoding.
Php (5 or lower) is known for its issues with multibyte encodings. Yet I originally had no problem at all with this.
I used to have an x86 (i.e. 32 bits) Linux installation. Under this architecture, I never caught any single issue with multibyte characters from UTF-8 (like the french é, à, ç, ê and others)
Alas, the situation became entirely different when I converted my installlation to the AMD64 architecture (64 bits). From this point on (and to this day), I could not exchange any string in UTF-8 between mysql and php, unless said sting contains only singlebyte characters...
I found a workaround involving "SET NAMES LATIN1," utf8_encode and utf8_decode to talk between php and my database, but it's not close to satisfying since it mostly defeats the benefit of using UTF-8 over LATIN1... See below for example my database request script.
It is important to stress again that the issue is entirely 64bits-specific.
Someting else I don't understand is that (even now, under 64 bits), php has no problem whatsoever handling UTF-8 that comes out of text files, yet it can't handle the UTF-8 that comes out of mysql requests.
Here's how I work around this issue:
Code: Select all
<?php
// Connexion et sélection de la base
if (!isset($connection)) {
$connection = new mysqli("localhost", "xxxxx", "xxxxxxx");
if (mysqli_connect_errno($connection)) {
die(implode("",array("Connexion au serveur uchronique impossible: ERREUR ", strval(mysqli_connect_errno($connection)), ", ", mysqli_connect_error($connection))));
[color=#FF0000]$connection->query("SET NAMES 'latin1'")[/color] or die(implode("",array("multicodisation uchronique impossible: ERREUR ", strval(mysqli_connect_errno($connection)), ", ", mysqli_connect_error($connection))));
}
// Sélection de la base de donnée
$connection->select_db("xxxxxxxx")
or die(implode("",array("Echec lors de la sélection de la base uchronique: ERREUR ", strval($connection->errno), ", ", $connection->error)));
}
$MessageConnect[$MSQLInd] = "Connexion uchronique réussie;";
// Sélection de la base de donnée
$connection->select_db("xxxxxxxx")
or die(implode("",array("Echec lors de la sélection de la base uchronique: ERREUR ", strval($connection->errno), ", ", $connection->error)));
// Exécuter la requêtes SQL
[color=#FF0000]$result = $connection->query(utf8_decode($request))[/color]
or die(implode("",array("Echec de la requête uchronique: ERREUR ", strval($connection->errno), ", ", $connection->error)));
if (strtoupper(substr($request,0,5)) === "SELEC" or strtoupper(substr($request,0,5)) === "SHOW " or strtoupper(substr($request,0,5)) === "DESCR" or strtoupper(substr($request,0,5)) === "EXPLA") {
//Nombre de résultats de la recherche
$MessageRequest[$MSQLInd] = implode("",array("<b>", $result->num_rows, "</b> résultat(s) répond(ent) à votre requête."));
$debug[] = $MessageConnect[$MSQLInd];
$debug[] = $MessageRequest[$MSQLInd];
// Construction du tableau de résultats
while ($row = $result->fetch_assoc()) {
// $RequestResult[$MSQLInd][] = $row;
[color=#FF0000]$RequestResult[$MSQLInd][] = array_map(utf8_encode,$row);[/color]
}
// Libération des résultats
$result->close();
}
// Fermeture de la connexion NE PAS DECOMMENTER
//$connection->close();
?>Anyone can tell me where it comes from, I mean, specifically why it happens only under a 64-bits architecture? Why it happens with mysql requests results but not with text file contents?
Can you point me to a bug report describing this issue with 64 bits architectures? This could be specific to Linux's AMD64, I don't know what happens with Windows XP or Vista 64bits, or Linux x86_64.
Can you suggest a workaround better than the one I'm using? Better in this sense would mean that it'd preserver the ability to handle characters which do not exist in Latin1 (japanese, chinese, ...)
Thanks by advance.
EDIT: I just find out that for some reason, and while not tied directly to a particular php version or a particular mysql server version, the problem ceases to occur when the client API version that php uses for mysql/mysqli is 5.1.30.