Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to tell horde 3.3.11 to use UTF-8 for it's mysql connection? The $conf['sql']['charset'] only tells horde what is expected from the database.

Horde uses MDB2 to connect to mysql. Is there way to force MDB2 or mysql character_set_client from php.ini?

So far I found two workarounds:

  • Force mysql to ignore character set requested by client

  • Force mysql to run SET NAMES utf8 on every connection

    init-connect='SET NAMES utf8'

Both have drawbacks on multi user mysql server. The first disables converting character sets alltogether and the second one forces every connection to produce UTF-8.


Found the problem. The 'charset' parameter was unset the last minute before sending to SQL backend. This is probably due to mysql not being able to digest utf-8 but utf8. Mysql specific mapping is required to make it work.

I just worked around it by translating utf-8 -> utf8. Won't work with any other databases with this patch though.

--- lib/Horde/Share/sql.php.orig    2011-07-04 17:09:33.349334890 +0300
+++ lib/Horde/Share/sql.php 2011-07-04 17:11:06.238636462 +0300
@@ -753,7 +753,13 @@
         /* Connect to the sql server using the supplied parameters. */
         require_once 'MDB2.php';
         $params = $this->_params;
-        unset($params['charset']);
+        if ($params['charset'] == 'utf-8') {
+            $params['charset'] = 'utf8';
+        } else {
+            unset($params['charset']);
+        }
         $this->_write_db = &MDB2::factory($params);
         if (is_a($this->_write_db, 'PEAR_Error')) {
             Horde::fatal($this->_write_db, __FILE__, __LINE__);
@@ -792,7 +798,13 @@
         /* Check if we need to set up the read DB connection seperately. */
         if (!empty($this->_params['splitread'])) {
             $params = array_merge($params, $this->_params['read']);
-            unset($params['charset']);
+            if ($params['charset'] == 'utf-8') {
+                $params['charset'] = 'utf8';
+            } else {
+                unset($params['charset']);
+            }
             $this->_db = &MDB2::singleton($params);
             if (is_a($this->_db, 'PEAR_Error')) {
                 Horde::fatal($this->_db, __FILE__, __LINE__);
share|improve this question
I just found out, the unset($params['charset']) -lines are there for a reason. See horde has utf-8 but mysql has utf8. So mapping is needed. It seems the problem has been fixed by ignoring it. – jkj Jul 4 '11 at 14:03

I thought $conf['sql']['charset'] is all you need to set, surely the character set is detected automatically wherever this is ignored. Is this actually not working for you?

share|improve this answer
No. And I really doubt it is working for anyone. For some reason conversions are done right outside Address Book (turba), but event there the SQL connection is still latin1 and only latin1 symbols can get through. (Even if the setting is utf-8) – jkj Jun 30 '11 at 13:17
So you think Horde should be providing you with an option to select the charset for this particular MySQL connection? – SuperBOB Jun 30 '11 at 13:28
I'd like to be able to get UTF-8 through the connection. No matter where it is configure. It'd be better if there was no need for workarounds in mysql configuration. – jkj Jun 30 '11 at 13:34
This is a comment, not an answer. – JakeGould May 11 '14 at 16:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.