View Single Post

   
  #12 (permalink)  
Old 04-08-2008, 03:38 PM
Peter H. Coffin
 
Posts: n/a
Default Re: Mysql database in UTF8, PHP shows latin1 (iso-8859-1)

On Tue, 08 Apr 2008 12:57:29 +0200, Willem Bogaerts wrote:
>>>> character_set_client=latin1
>>> That is a problem I also had. the [mysql] section of my.cnf is for the
>>> command-line client only. A [client] section may or may not be used for
>>> PHP connections. I had to send a "SET NAMES utf8" upon connection to
>>> really convince MySQL to use utf8 for the connection.

>>
>> That's how it's supposed to be and was already mentioned multiple times.
>> How else should MySQL know what connection encoding the PHP client and
>> your scripts prefer?

>
> You should either be able to configure it reliably OR have a default
> encoding. The way it is now, this is not the case. If you send an SQL
> file through the command-line client, the default encoding can be
> DIFFERENT from the situation where you send the exact same file through
> PHP. That is the problem here. The whole command "SET NAMES utf8" is not
> even legible if the encoding is set to ucs-2. That is why that
> encoding is not possible in MySQL.


Don't be silly. ucs2, utf16 and utf32 cannot be used for SET NAMES or SET
CHARACTER SET. It's in the manual, in the section about connection
charsets. You DID read that section, didn't you, before complaining that
connection charsets make no sense?

> Off course, the default encoding should be passed in the connection.
> Can you tell me what the default encoding is when connecting?
> According to the manual, any "language character" can be used to use
> for a database name. So mysql_select_db() will not use latin-1, as you
> would not be able to refer to your database. Or is it? I could not
> find it anywhere.


It's whatever you use on the --default-character-set=charset_name
option, or in the my.cnf file, or latin-1, in that order. This is a lot
less hard if you try reading and knowing the documentation that
accompanies your installation.

>>> This really sucks, off course. It is plain stupid to have to set
>>> the encoding used encoded in the encoding it has to set. It is like
>>> sending a key INSIDE a safe which requires that key to open it.

>>
>> You connect to the DB using the default encoding and then set it to
>> whatever you want it to be. There's nothing stupid about that.
>>
>> Micha

>
> The problem with that, off course, is that this is highly vendor,
> version AND client-specific. The command-line client behaves
> differently than a PHP initiated connection if you do not send it.


That's why you send it, whenever you are unsure of what it is currently
set to. This is as ridiculous as complaining about having to explicitly
open a connection to mysql in PHP as well, and feeling hurt that you
have to specify which database you want to use. "Why not have a sensible
default database and just use that?!?"

> Now that was the exact problem of the original poster. And older
> database versions do not even understand it.


How old a database do you HAVE? The first note on the connection charset
page in the online manual is from 2004.

--
The Web brings people together because no matter what kind of a twisted
sexual mutant you happen to be, you've got millions of pals out there.
Type in 'Find people that have sex with goats that are on fire' and the
computer will ask, 'Specify type of goat.' -- Rich Jeni
Reply With Quote