For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > February 2007 > Re: [PHP-DB] What effects MySQL connection's character set









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PHP-DB] What effects MySQL connection's character set
Chris

2007-01-30, 3:58 am

Niel Archer wrote:
> Hi all
>
> How is the character set of returned data effected? I have a DB using
> UTF-8 encoding., PHP is set to use UTF-8 internally. However the MySQL
> connection returns Latin1 data. How can I get it to return UTF-8 data
> instead.


http://dev.mysql.com/doc/refman/4.1...et-literal.html

Should cover your questions :)

--
Postgresql & php tutorials
http://www.designmagick.com/
Niel Archer

2007-01-30, 6:58 pm

Hi Chris.

Thanks for this. That page didn't actually help, but one of the follow
ups did. Apparently, despite being setup as UTF-8 throughout the Db,
tables, and columns. The returned data still can default to Latin1.
I've forced my test server to return UTF-8 (I hope) and am trying it
out today. Fingers crossed!

Niel
Niel Archer

2007-01-30, 6:58 pm

Hi

> Thanks for this. That page didn't actually help, but one of the follow
> ups did. Apparently, despite being setup as UTF-8 throughout the Db,
> tables, and columns. The returned data still can default to Latin1.
> I've forced my test server to return UTF-8 (I hope) and am trying it
> out today. Fingers crossed!


That turned out to be overly optimistic. Even Though the server is
using UTF-8 throughout, it still defaults to latin1 on connections. So
I used the SET NAMES utf8. It still will not work as I expect. I used
the following code to test it.

$Db = new mysqli($Host, $User, $Pass, $Db);

$Db->query("SET NAMES utf8");
$result = $Db->query("SHOW VARIABLES LIKE 'character\_set\_%'");

$count = $result->num_rows;
while ($count):
$dummy = $result->fetch_assoc();
print $dummy['Variable_name'] . " = " . $dummy['Value'] . "\n";
--$count;
endwhile;

print "\ncharacter_set_name: " . $Db->character_set_name() . "\n";

Which results in the following output:

character_set_client = utf8
character_set_connection = utf8
character_set_database = utf8
character_set_results = utf8
character_set_server = utf8
character_set_system = utf8

character_set_name: latin1

I can't find any documentation on PHP's character encoding, beyond the
default_charset directive. Several of the functions/extensions have
documentation, but not PHP itself.
I suspect the problem is with php itself or the mysqli extension,
which was my original thought and reason for my post.

Anyone have any ideas?


Niel
Niel Archer

2007-01-31, 6:58 pm

Hi all

Finally identified the problem. Was pretty obvious in retrospect.

The mysqli class (Improved MySQL extension OO style) defaults to
latin1 as a character set, regardless of what PHP is using. Simple
solution is to use the set_charset method (mysqli_set_charset for non OO) on
the object, which will change the connection parameter.

Niel
Gunawan Wibisono

2007-02-03, 3:58 am

what i read..
i conclusion. whenever the data is.. is always latin1 right??
if the data seem give strange type (example like japanese font).. it
will stay on latin1 or change into apropriate data

On 2/1/07, Niel Archer <niel@catweasel.org> wrote:
> Hi all
>
> Finally identified the problem. Was pretty obvious in retrospect.
>
> The mysqli class (Improved MySQL extension OO style) defaults to
> latin1 as a character set, regardless of what PHP is using. Simple
> solution is to use the set_charset method (mysqli_set_charset for non OO) on
> the object, which will change the connection parameter.
>
> Niel
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



--
akan ada dimana mulut terkunci dan suara tak ada lagi..
saat itu gunakanlah HP untuk melakukan SMS!!
-> ini aliran bedul.. bukan aliran aneh.
tertawa sebelum tertawa didepan RSJ..
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com