On 2006-04-12 13:25:49 -0500, Paul DuBois wrote:
> On 4/12/06 13:03, "Peter J. Holzer" <[EMAIL PROTECTED]> wrote:
> > This just cost me a few hours of debugging, so I am posting it to spare
> > others:
> >
> > The mysql client character set can be set to UTF-8 with:
> >
> > $dbh->do("set character set utf8");
> > $dbh->do("set names 'utf8'");
>
> How does the result differ from simply using set names by itself?
None, apparently. At least for my test cases. And rereading the mysql
manual I think that you should use either of them, not both.
I think I can now explain the strange results (I could insert some
Non-ASCII characters, but not some others) I had:
The database I was using had a number of tables with character set
utf8, but the default character set of the database was still latin1.
The difference between set character set and set names seems to be that
set names sets the connection character set to the character set
specified, while set character set sets it to the default character set
of the database. So, with set character set utf8 in effect, mysql server
was converting all strings it got from the client first to latin1
(replacing all non-latin1 characters with question marks) and then back
to utf8 to insert them into the tables.
So I guess the real advice is:
* Either make sure your database default character set is a superset of
all the characters sets in your tables and use "set character set"
* or use "set names".
hp
--
_ | Peter J. Holzer | If I wanted to be "academically correct",
|_|_) | Sysadmin WSR | I'd be programming in Java.
| | | [EMAIL PROTECTED] | I don't, and I'm not.
__/ | http://www.hjp.at/ | -- Jesse Erlbaum on dbi-users
pgp60ma3GEN8I.pgp
Description: PGP signature
