[英]Symfony4 data from the database is not utf8 encoded
為什么datebase中的數據未進行utf8編碼? utf8mb64_general_ci為每個列,表和日期數據庫本身設置。 我的doctrine.yaml如下:
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
我仍然得到例如“Ogólne”的“Ogólne”插圖。
該問題僅在生產中發生。 本地編碼可以。 我在生產環境上使用MySQL 5.7,在本地使用MariaDB 10.1。
我知道了。
我在doctrine.yaml的dbal配置中添加了以下這段代碼,並且可以正常工作!!!
options:
1002: "SET NAMES 'UTF8'"
發生的數據庫連接是拉丁編碼的,並且上面的代碼強制執行utf8。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.