I’m using Symfony 2.1.6 framework integrated with Propel 1.6.7 as database ORM through a MySQL Server 5.5.28 and I’m having problem to set database collation to utf8_unicode_ci.
My app/config/config.yml:
...
propel:
dbal:
driver: %database_driver%
user: %database_user%
password: %database_password%
dsn: "%database_driver%:host=%database_host%;dbname=%database_name%;charset=%database_charset%"
options:
MYSQL_ATTR_INIT_COMMAND: "SET NAMES utf8 COLLATE utf8_unicode_ci"
attributes: {}
(parameters are already defined in app/config/parameters.yml)
Without options it works, but with charset issues (MySQL defaults to utf8_general_ci collation, but database schema was defined with utf8_unicode_ci). If I use options as above Propel/Symfony raise a bunch of exceptions:
in /var/www/vendor/propel/propel1/runtime/lib/Propel.php at line 725 -+
at ErrorHandler ->handle ('2', 'Illegal string offset 'value'', '/var/www/vendor/propel/propel1/runtime/lib/Propel.php', '725', array('source' => array('MYSQL_ATTR_INIT_COMMAND' => 'SET NAMES utf8 COLLATE utf8_unicode_ci'), 'write_to' => array(), 'option' => 'MYSQL_ATTR_INIT_COMMAND', 'optiondata' => 'SET NAMES utf8 COLLATE utf8_unicode_ci', 'key' => '1002'))
in /var/www/vendor/propel/propel1/runtime/lib/Propel.php at line 725 -+
at Propel ::processDriverOptions (array('MYSQL_ATTR_INIT_COMMAND' => 'SET NAMES utf8 COLLATE utf8_unicode_ci'), array())
in /var/www/vendor/propel/propel1/runtime/lib/Propel.php at line 668 -+
at Propel ::initConnection (array('dsn' => 'mysql:host=127.0.0.1;dbname=symfony;charset=utf8', 'user' => 'root', 'password' => '********', 'classname' => 'DebugPDO', 'options' => array('MYSQL_ATTR_INIT_COMMAND' => 'SET NAMES utf8 COLLATE utf8_unicode_ci'), 'attributes' => array(), 'settings' => array()), 'default')
in /var/www/vendor/propel/propel1/runtime/lib/Propel.php at line 576 -+
at Propel ::getMasterConnection ('default')
in /var/www/vendor/propel/propel1/runtime/lib/Propel.php at line 602 -+
at Propel ::getSlaveConnection ('default')
in /var/www/vendor/propel/propel1/runtime/lib/Propel.php at line 552 -+
at Propel ::getConnection ('default', 'read')
in /var/www/vendor/propel/propel1/runtime/lib/query/ModelCriteria.php at line 1160 -+
at ModelCriteria ->find ()
in /var/www/src/Acme/AppBundle/Controller/DefaultController.php at line 20 -+
at DefaultController ->fooAction ()
at call_user_func_array (array(object(DefaultController), 'fooAction'), array())
in kernel.root_dir/bootstrap.php.cache at line 1426 -+
at HttpKernel ->handleRaw (object(Request), '1')
in kernel.root_dir/bootstrap.php.cache at line 1390 -+
at HttpKernel ->handle (object(Request), '1', true)
in kernel.root_dir/bootstrap.php.cache at line 1566 -+
at HttpKernel ->handle (object(Request), '1', true)
in kernel.root_dir/bootstrap.php.cache at line 617 -+
at Kernel ->handle (object(Request))
in /var/www/web/app_dev.php at line 25 -+
I know that I can change my.cnf to define MySQL default collation directly from server config, but I need to set this at runtime… Am I missing something? How I should set MYSQL_ATTR_INIT_COMMAND in app/config/config.yml?
If you see source code here,
Its expecting an “value” key in option data, so try this
Or
you can also define queries which has to be executed immediately after connection opened
FYI: https://github.com/propelorm/PropelBundle/blob/1.1/Resources/doc/configuration.markdown
Propel runtime configuration file