Client mysql and server mysql character set and encoding

Hi,

I use mysql 5.5.8.
I have already created a database and defined character set with this:

CREATE DATABASE IF NOT EXISTS example_db
   CHARACTER SET utf8
   COLLATE utf8_general_ci;

doing this, all tables I create have the same charset and collation.

My question is:
Please can you tell me why if I execute the PHP function mysql_client_encoding() it retrieves latin1 and not utf-8?

many thanks.

…if I execute the PHP function mysql_client_encoding() it retrieves latin1 and not utf-8?

is this in your web page? If so, your server config may need to be changed to output utf8 or you can set the meta in your web page

<meta http-equiv=“Content-Type” content=“text/html; charset=utf8” />

hth

bazz

yes in my web page. But however I have already set the character set as utf-8 in html code with this line of code:

<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >

I have to set the charset with this php command mysql_set_charset() to obtain the right charset.
But I don’t understand why I have to do this.

If in the client side I use my browser, the client charset would be the same of my browser or not? Why I have to use mysql_set_charset() to set utf-8?

many thanks.

As I understand it, the server outputs the charset as per the server config. so if you need to display it differently, you need to place this line in your html head section.

note the lack of a hyphen :wink:

<meta http-equiv=“Content-Type” content=“text/html; charset=utf8” />

when you run your page through the validator, if the line of code sets a charset different from that of the server, it’ll tell you. (well, it tells me for my pages).

But tell me; how is this a mysql question? you should have posted this in the php forum
bazz

I think this is a mysql issue.
If I execute this sql statement:

SHOW VARIABLES LIKE 'character_set%'

I obtain this:


Variable_name 	                Value
character_set_client             utf8
character_set_connection      utf8
character_set_database        utf8
character_set_filesystem       binary
character_set_results            utf8
character_set_server             latin1
character_set_system            utf8
character_sets_dir               c:\\wamp\\bin\\mysql\\mysql5.5.8\\share\\charsets\\

What is character_set_client?
Does the php function mysql_client_encoding() refers at that one?
Why on my browser window I obtain latin1 even if with this sql statement I obtain character_set_client=utf-8?

your issue is relating to how the web page is outputted by your server. No to do with MySQL, I think.

Anyhoo, as I wrote earlier, the server is sending latin 1 to your browser. You need to add the meta content line to your webpage as shown earlier.

I’ll try to have a mod move this to php.

bazz

You need to add the meta content line to your webpage as shown earlier.

In my web page already exists that line!

However adding some lines within the file my.ini it goes rightly:
(as you can read in this: Configuring the Character Set and Collation for Applications)

[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci

and so character_set_sever has been set to utf-8.

But the question is why I have to specify the charset for every connection even if during the creation of my database I have already declared utf-8 charset? It seems a bit redundant… :confused: Does someone has an answer? thanks.