Symfony学说charset问题



我正在尝试学习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: 'AppEntity'
                alias: App

我也尝试了默认配置:

 charset: utf8mb4
    default_table_options:
        charset: utf8mb4
        collate: utf8mb4_unicode_ci

字符集utf8不存在,但是UTF-8(所有CAPS)。根据Microsoft的PDO_SQLSRV文档:

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

  1. 确保源或目标列是NCHAR类型或Nvarchar。

  2. 在参数阵列中指定PHP类型为SQLSRV_PHPTYPES_STRING('utf-8')。或者,将" tarneet" =>" utf-8"指定为连接选项。

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

您可以将UTF-8或SQLSRV_ENC_CHAR传递给字符,但是您不能传递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)%'

最新更新