我正在使用與Propel 1.6.7集成的Symfony 2.1.6框架作爲數據庫ORM,通過MySQL服務器5.5.28,我有問題需要將數據庫整理設置爲utf8_unicode_ci
。Symfony + Propel:設置連接整理
我應用程序/配置/ 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: {}
沒有options
它的工作原理,但字符集(參數在應用程序/配置/ parameters.yml已定義)問題(MySQL默認爲utf8_general_ci
歸類,但數據庫模式定義爲utf8_unicode_ci
)。如果我使用options
作爲波輪/ Symfony的上面提高了一堆異常:
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 -+
我知道,我可以改變my.cnf中直接從服務器配置定義MySQL的默認排序規則,但我需要將此設置爲運行時...我錯過了什麼嗎?我應該如何設置MYSQL_ATTR_INIT_COMMAND
app/config/config.yml?