douzhong2954 2018-12-10 23:06
浏览 148

来自数据库的Symfony4数据不是utf8编码的

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.

  • 写回答

1条回答 默认 最新

  • drfkl66684 2018-12-11 20:44
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误