List:General Discussion« Previous MessageNext Message »
From:Santiago del Castillo Date:July 6 2006 4:37pm
Subject:PHP connects in Latin1 when it should do it in UTF-8
View as plain text  
Hi, i'm having a bit of a headache with PHP and MySQL, i've some questions:


1) I've a database in UTF-8 and when i connect to it with mysql_connect,
and exec a query with mysql_query, the results are in latin1. (i proved
this with mysql_query("show variables like 'char%'");
2) Is there any way to force mysql to make connections in utf8?

here is the mysql status command report:

-----[*code*]-----

mysql> status
--------------
mysql  Ver 14.12 Distrib 5.0.22, for redhat-linux-gnu (x86_64) using
readline 5.
0

Connection id:          304
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.0.22
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8
Db     characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:            /var/lib/mysql/mysql.sock
Uptime:                 21 hours 12 min 22 sec

Threads: 1  Questions: 63783  Slow queries: 0  Opens: 0  Flush tables: 1
  Open t
ables: 49  Queries per second avg: 0.835
--------------

-----/[*code*]-----



-----[*code*]-----

mysql> show variables like 'char%';
+--------------------------+----------------------------+
| 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     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

-----/[*code*]-----

I use FC5 and a fresh mysql install, the default encoding is in latin1. 
As you can see i setup all charsets are in UTF-8. And, even with this, 
PHP still connects to the DB in latin1.



I don't know what else to do..
I don't want to do a mysql_query("set names utf8") at the beginning when
somebody opens the page because it a site with >100k hits per second
(that menas >200k qps).

There must be a solution.


Thanks!
Santiago

Thread
PHP connects in Latin1 when it should do it in UTF-8Santiago del Castillo6 Jul
  • Re: PHP connects in Latin1 when it should do it in UTF-8Eric Butera7 Jul
    • Re: PHP connects in Latin1 when it should do it in UTF-8Santiago del Castillo10 Jul