php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #33604 MYSQL: php.ini option to set character_set and allow using UTF8
Submitted: 2005-07-07 15:43 UTC Modified: 2011-01-31 11:47 UTC
Votes:8
Avg. Score:4.6 ± 0.7
Reproduced:7 of 8 (87.5%)
Same Version:0 (0.0%)
Same OS:3 (42.9%)
From: dlacroix at erasme dot org Assigned: mysql (profile)
Status: Duplicate Package: MySQL related
PHP Version: 5.0.4 OS:
Private report: No CVE-ID: None
 [2005-07-07 15:43 UTC] dlacroix at erasme dot org
Description:
------------
There is no option in php.ini to setup the character set used with the MySQL connection.

I'm using PHP in UTF-8 per default, MySQL 4.1.11 in UTF-8 but when I open a connection with PHP-MySQL it use latin1.

I need an option to set the character set to UTF-8 when a connection is opened like in my.cnf file for mysql client.

I have written a patch for php-mysql-5.0.4.

It add mysql.default_character_set variable. Like that you can set:

mysql.default_character_set = utf8

I still have a problem with mysql_client_encoding function that return latin1 even if the database is well using UTF-8. But it seems to be a MySQL client problem.

Without this patch PHP program like SPIP are missusing the database and thing can be double encoded in UTF-8.

This patch just add the following MySQL command when a connection is opened:

SET character_set_client=choosed value
SET character_set_connection=choosed value
SET character_set_results=choosed value

Reproduce code:
---------------
Patch is available here:

http://index.erasme.org/php-5.0.4-mysql-characterset.patch

else you can ask me (dlacroix@erasme.org)


Patches

mysql.connect_charset.patch (last revision 2010-07-24 23:56 UTC by mabi at gentoo dot org)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-25 02:02 UTC] mabi at gentoo dot org
Just attached the patch gentoo currently ships for this.
In short: it provides a mysql.connect_charset php.ini option and uses mysql_options so that each connection will have this charset set by default.

We use a similar patch for mysqli.

The patch is not mine (I just adapted it to work with php-5.3.3), the original credits are:
Initial patch by Stuart (?) and CHTEKK
Updated for 5.3 by hoffie
 [2011-01-01 23:42 UTC] jani@php.net
-Package: Feature/Change Request +Package: MySQL related
 [2011-01-06 17:12 UTC] uw@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: mysql
 [2011-01-06 17:12 UTC] uw@php.net
Duplicate of http://bugs.php.net/bug.php?id=44118
 [2011-01-31 11:47 UTC] johannes@php.net
-Status: Assigned +Status: Duplicate
 [2011-01-31 11:47 UTC] johannes@php.net
Duplicate, as ulf said.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 20:01:28 2024 UTC