Symfony 学说字符集问题

问题描述 投票:0回答:2

我正在尝试学习

symfony
并通过各种示例进行工作。主要问题是我真的不知道如何配置
doctrine.yaml

我正在使用

SQLSRV

当我加载时

php bin/console doctrine:fixtures:load --append
出现错误:
SQLSTATE [IMSSP, -48]: The encoding 'utf8' is not a supported encoding for the CharacterSet connection option.

我的学说配置是:

doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_sqlsrv'
        charset: utf8
        default_table_options:
            charset: utf8
            collate: utf8_general_ci

        url: '%env(resolve:DATABASE_URL)%'
    orm:
        auto_generate_proxy_classes: true
        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

我也尝试了默认配置:

 charset: utf8mb4
    default_table_options:
        charset: utf8mb4
        collate: utf8mb4_unicode_ci
php symfony doctrine-orm
2个回答
2
投票

字符集

utf8
不存在,但
UTF-8
(全部大写)存在。根据微软的PDO_SQLSRV文档

向服务器发送或检索 UTF-8 编码数据:

  1. 确保源列或目标列的类型为 nchar 或 nvarchar。

  2. 在参数数组中将 PHP 类型指定为 SQLSRV_PHPTYPE_STRING('UTF-8')。或者,指定“CharacterSet”=>“UTF-8”作为连接选项。

    当您指定字符集作为连接选项的一部分时,驱动程序假定其他连接选项字符串使用相同的字符集。服务器名称和查询字符串也假定使用相同的字符集。

您可以将UTF-8或SQLSRV_ENC_CHAR传递给CharacterSet,但不能传递SQLSRV_ENC_BINARY。默认编码是 SQLSRV_ENC_CHAR。

您可能想尝试以下方法:

doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_sqlsrv'
        charset: UTF-8
        url: '%env(resolve:DATABASE_URL)%'

0
投票

好的,我刚刚发现了问题。该问题与字符集无关。该问题与环境文件的滥用有关。 env.local 处于活动状态,并且默认设置为 utf8。我更改了 .env.local 文件而不是 .env,问题现已解决。

© www.soinside.com 2019 - 2024. All rights reserved.