Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 Charset for queries parameters

I have a project in Symfony2 which works good at my localhost, but after moving it to external server problem has started.

  1. I don't see any results names from database which contains polish characters
  2. In Profiler i checked queries:
    • 'Parameters' section has correct charset
    • 'runnable query' has the same parameters but with bad charset

for example:

(...) WHERE ((((c1_.name LIKE '%Å�%') OR (c3_.name LIKE '%Å�%') OR (..) Parameters: ['%ś%', '%ś%', (...)]

All database tables has charset = utf8_unicode_ci.

In config.yml i set

doctrine: 
    dbal: 
      charset: UTF8 

Setting framework charset doesn't work.

/config.php test says:

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".

But unfortunatelly i have no access to php.ini on that server. Is that possible magic_quotes_gpc caused that problem? I don't have access to command line too, so i have added project (database, file system, vendors) via ftp, and phpmyadmin.

Becouse I don't have problem on my localhost i guess that is problem with server configuration, and I have no access to that, the only way I see is to try to change charset configuration of QueryBuilder. Where can I do that? Do you know what else could cause that problem?

Thanks

like image 310
user1826876 Avatar asked Nov 15 '12 14:11

user1826876


1 Answers

Found solution: To set "SET NAMES utf8" I changed my doctrine config

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'"

It works fine now.

like image 102
user1826876 Avatar answered Oct 21 '22 14:10

user1826876