Symfony2 Charset for queries parameters
Asked Answered
I

1

7

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

Ibis answered 15/11, 2012 at 14:47 Comment(2)
Have you compared phpinfo(); on both servers? Else, is your external web server running utf-8? (AddDefaultCharset UTF-8, php_value default_charset "UTF-8" inside htaccess)Fourcycle
I've set charsets UTF8 as you said, and compared phpinfos fields with charsets. They are the same but problem is still there. I read that this server is running by default latin2, so i've tried to change everything to latin2 but that didn't help. I'm trying to find place/function which replace '?' signs with elements from parameters array. Is that PDOStatment job? How can I check what is going on there step by step?Ibis
I
10

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.

Ibis answered 5/12, 2012 at 10:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.