0

Why data from datebase is not utf8 encoded? utf8mb64_general_ci is set for every column, table and datebase itself. My doctrine.yaml is below:

parameters:
# Adds a fallback DATABASE_URL if the env var is not set.
# This allows you to run cache:warmup even if your
# environment variables are not available yet.
# You should not need to change this value.
env(DATABASE_URL): ''

doctrine:
dbal:
    # configure these for your database server
    driver: 'pdo_mysql'
    server_version: '5.7'
    charset: utf8mb4
    default_table_options:
        charset: utf8mb4
        collate: utf8mb4_unicode_ci

    url: '%env(resolve:DATABASE_URL)%'
orm:
    auto_generate_proxy_classes: '%kernel.debug%'
    naming_strategy: doctrine.orm.naming_strategy.underscore
    auto_mapping: true
    mappings:
        App:
            is_bundle: false
            type: annotation
            dir: '%kernel.project_dir%/src/Entity'
            prefix: 'App\Entity'
            alias: App

Still I get e.g "Og�lne" insetead of "Ogólne".

enter image description here

The problem only occurs on production. Locally encoding is OK. I use MySQL 5.7 on production and MariaDB 10.1 locally.

zsDev
  • 68
  • 1
  • 7
  • See "black diamond" in https://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored – Rick James Dec 10 '18 at 23:20

1 Answers1

0

I've figured it out.

I have added this piece of code below in dbal configuration in doctrine.yaml and it works!!!

options:
    1002: "SET NAMES 'UTF8'"

It occurred db connection was latin encoded and code above enforce utf8.

zsDev
  • 68
  • 1
  • 7