我在 Symfony2 中有一个项目,它在我的本地主机上运行良好,但是在将其移动到外部服务器后问题已经开始。
例如:
(...)
WHERE ((((c1_.name LIKE '%�%') OR (c3_.name LIKE '%�%') OR (..)
Parameters: ['%ś%', '%ś%', (...)]
所有数据库表都有 charset = utf8_unicode_ci。
在 config.yml 我设置
doctrine:
dbal:
charset: UTF8
设置框架字符集不起作用。
/config.php 测试说:
RECOMMENDATIONS:
1. Install and enable a PHP accelerator like APC (highly recommended).
2. Set short_open_tag to off in php.ini*.
3. Set magic_quotes_gpc to off in php.ini*.
* Changes to the php.ini file must be done in "/usr/local/php/php.ini".
但不幸的是,我无法访问该服务器上的 php.ini。是不是magic_quotes_gpc 导致了这个问题?
我也无法访问命令行,所以我通过 ftp 和 phpmyadmin 添加了项目(数据库、文件系统、供应商)。
因为我的本地主机没有问题,我想这是服务器配置的问题,我无法访问它,我看到的唯一方法是尝试更改 QueryBuilder 的字符集配置。我在哪里可以这样做?你知道还有什么可能导致这个问题吗?
谢谢
最佳答案
找到解决方案:
要设置“SET NAMES utf8”,我更改了我的学说配置
doctrine:
dbal:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
charset: UTF8
options:
1002: "SET NAMES 'UTF8'"
它现在工作正常。
关于查询参数的 Symfony2 字符集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13399912/