Edit report at https://bugs.php.net/bug.php?id=44118&edit=1

 ID:                 44118
 Updated by:         and...@php.net
 Reported by:        slava_reg at nsys dot by
 Summary:            [PATCH] MySQL: Set connection charset via php.ini
                     option
 Status:             Wont fix
 Type:               Feature/Change Request
 Package:            MySQL related
 Operating System:   any
 PHP Version:        5.2.5
 Assigned To:        mysql
 Block user comment: N
 Private report:     N

 New Comment:

1. AFAIK the MySQL parser can't use UTF32 this is why SET NAMES doesn't work
2. Executing SET NAMES is the most improper way to change character set
3. The proper way is to use mysqli_options(), which is mysqli only
4. ext/mysql is deprecated and won't get changed
5. Example
$c=mysqli_init();
$c->options(MYSQLI_SET_CHARSET_NAME, "utf8");
$c->connect(....);
during handshake utf8 will become the charset to be used to talk to the MySQL 
parser.  Or maybe in the future MySQL will have a parser that accepts UTF16 and 
UTF32. By using mysqli_options() there is no additional round-trip to the 
server and the client library knows which character set is really in use, thus 
mysqli_real_escape_string() will correctly.


Previous Comments:
------------------------------------------------------------------------
[2013-02-06 03:15:16] shane dot bester at oracle dot com

in my above case, i can connect only if i start server with 
--skip-character-set-
client-handshake option

------------------------------------------------------------------------
[2013-02-06 03:09:05] shane dot bester at oracle dot com

I compiled my server with default charset of utf32.  Now I cannot connect at 
all, 
therefore cannot execute any SET NAMES command.  So, this needs fixing.

PHP Warning:  mysqli_connect(): (HY000/1231): Variable 'character_set_client' 
can't be set to the value of 'utf32' in X line Y

------------------------------------------------------------------------
[2011-10-18 12:58:41] and...@php.net

mysqli has this. You can create a connection with mysqli_init() or just new 
mysql() and then call mysqli_options() or $link->options and set the charset to 
be used. It will be negotiated during the client-server handshake and there 
will be no additional query like SET NAMES. mysqli_options() works before 
connections is established, later it has no effect.

------------------------------------------------------------------------
[2011-02-24 14:15:45] cavo at ynet dot sk

This is not about making application utf8 compatible. You can do this by "set 
names" query. But it may be redundant. For example: All my database is in utf8 
encoding. All my pages have content-type utf8. All form posts from clients are 
in utf8. All strings I process in application are utf8. But what do I need to 
do right after I connect to database? - "set names utf8;" Why? Because if I 
don't, db will re-encode all strings to latin1. And PHP don't care. If I have 
100 new connections to db per second, I need to 100 times run that query. Why 
if client and server could negotiate encoding in those 2 obliged packets? ( 
http://bugs.php.net/bug.php?id=54086 ). It's ok to set latin1 as default 
character set used by client to not affect existing applications (I believe 
mostly for those, who actualy don't know, what are they doing..). But I think 
it's very useful to have option to set encoding manualy via configuration 
option or in connect functions like: mysql_connect('localhost', 'user', 'pwd', 
true, MYSQL_CLIENT_ENCODING_UTF8);

Or am I somwhere wrong?

http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol#Client_Authentication_Packet
http://dev.mysql.com/doc/refman/5.5/en/server-options.html#option_mysqld_default-character-set
http://dev.mysql.com/doc/refman/5.5/en/server-options.html#option_mysqld_character-set-client-handshake
http://bugs.php.net/bug.php?id=54086

------------------------------------------------------------------------
[2011-01-31 11:52:36] johan...@php.net

The application has to know the encoding being used, else some strange things 
might happen. We have seen the trouble in having this globally configurable 
when Gentoo decided to use Utf-8 for their MySQL installations by default 
instead of MySQL's default. I doubt you can make an application Utf-8 
comaptible by just setting such a low-level switch (it won't affect the HTTP 
Content-type header or HTML forms, thus receiving data in a wrong encoding from 
the user, not re-encode it etc.)

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=44118


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=44118&edit=1

Reply via email to