Jump to content
  • Advertisement
Sign in to follow this  
PERECil

[web] Mysql: client not understanding the set up encoding

This topic is 4590 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, We're currently in the process of changing one of our web application to be fully in utf-8 encoding standard. However, I got a little problem: our php-mysql connector doesn't seems to take account the new encoding set up with SET NAMES. Here is an example:
<?php
function showVars($s)
{
  $r = mysql_query("SHOW VARIABLES LIKE '%char%'",$s);
  while($pResult=mysql_fetch_assoc($r))
	echo "variable name: ".$pResult["Variable_name"]." value: ".$pResult["Value"]."
"; } $s = mysql_connect("localhost","root",""); showVars($s); echo mysql_client_encoding($s)."
"; mysql_query("SET NAMES 'UTF8'",$s); showVars($s); echo mysql_client_encoding($s)."
"; ?>
The answer:
variable name: character_set_client value: latin1
variable name: character_set_connection value: latin1
variable name: character_set_database value: utf8
variable name: character_set_results value: latin1
variable name: character_set_server value: utf8
variable name: character_set_system value: utf8
variable name: character_sets_dir value: /usr/share/mysql/charsets/
latin1
variable name: character_set_client value: utf8
variable name: character_set_connection value: utf8
variable name: character_set_database value: utf8
variable name: character_set_results value: utf8
variable name: character_set_server value: utf8
variable name: character_set_system value: utf8
variable name: character_sets_dir value: /usr/share/mysql/charsets/
latin1
You can see that the character_set has been put to utf-8 with the "SET NAMES" command, but the client stays in latin1. Does someone have an idea about this problem? System configuration: the computer is configured with latin1 the server is fully utf-8 and run MySQL 4.1.15-Debian_1-log

Share this post


Link to post
Share on other sites
Advertisement
Maybe you need SET CHARACTER SET instead, or as well.

Why append ."" to all your output statements, by the way?

Share this post


Link to post
Share on other sites
I don't see what's wrong with that.

"SET NAMES utf8" must be done on a per-connection basis. Send it before you do any other SQL for each connection and you will be fine.

I've used it in several application and utf8 strings have been going into my datbase fine.

One thing I should warn you about though ... you still need to have the tables character sets in utf8 if you want to store unicode data. This can be done either in the CREATE TABLE statement, or you can set the database default charset before you start, then all your char columns will be utf8 unless you specify otherwise.

Mark

Share this post


Link to post
Share on other sites
The ."" is by the way a ."
";

I've tried with set character set too. And I know that the "SET NAMES" should be done everytime I create a new connection, but if you read the code carefully, I only made one connection.

Oh, and all my databases/tables are in utf8_general_ci.

Share this post


Link to post
Share on other sites
In which case, it is apparently wrong.

The mysql_ functions are the "old" way to access MySQL anyway- new applications should use mysqli or PDO::MySQL (Or some data layer which uses them)

mark

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!