Edit report at https://bugs.php.net/bug.php?id=44118&edit=1
ID: 44118
Comment by: shane dot bester at oracle dot com
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:
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
Previous Comments:
[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.)
[2011-01-06 16:19:52] u...@php.net
Not sure if this is really needed. It can be done in user land. Its a bit of a
convenience feature. Not many votes for it... Andrey, Johannes...?
[2008-02-14 13:00:54] slava_reg at nsys dot by
Description:
Hi,
As I'm tired of patching various user-installed php-engines to work correctly
with newer MySQL versions (4.1.x +) that require connection character set to be
specified, I decided to solve the problem at the php level.
So, I patched both mysql and mysqli extensions (based on an idea found
somewhere in internet).
Result is available at:
http://bubble.nsys.by/projects/patches/php/php-5.2.5-mysql-client-charset.patch
The patch introduces two more php.ini directives:
mysql.client_charset and
mysqli.client_charset
As those directives are optional, the patch shouldn't break any existing
functionality, but it could *really* help users who's native language is not
latin and who want to use some php-scripted engine with mysql 'out-of-the-box'.
Best,
Vladislav Bogdanov
--
Edit this bug report at https://bugs.php.net/bug.php?id=44118&edit=1