SQL Server列名称包含问号而不是俄语字符

时间:2017-06-08 07:32:19

标签: php sql-server encoding utf-8 yii2

我是sql server的新手,对编码知之甚少。我使用PHP 7,Yii2作为我的项目。

当前的数据库配置是:

'class' => 'yii\db\Connection',
'dsn' => 
'sqlsrv:Server=172.16.30.22,1433;Database=DEV_PM_TOOLS;ConnectionPooling=0',
'charset' => 'utf8',

当我尝试创建数据透视表(将不同的行值转换为列名)时,我的查询返回问号而不是俄语字符(错误编码的[ПТО0004]列。)。并且异常消息是Malformed UTF-8 characters, possibly incorrectly encoded.

0 => [
    'ItemKey' => '990'
    'ItemNo' => 'BO 3397118991'
    'CompanyKey' => '15'
    'Description' => 'Щітка склоочисника'
    'SearchDescription' => 'К-Т БЕСКАРКАСНЫЙ AEROTWIN 650/600 MM A991S RETROOFIT'
    'TopCode' => 'C'
    'ResponsibleBrandAnalyst' => 'EES0947'
    'ResponsibleBrandManager' => 'EES0947'
    'Grp' => 'СТЕКЛООЧИСТИТЕЛЬ'
    'SubGrp' => 'ЩЕТКИ СТЕКЛООЧЕСТИТЕЛЯ'
    'Brand' => 'BOSCH'
    'V00214' => null
    '���0004' => '14.2953'
    'PrimeCost' => '14.8400'
    'UnitPriceD3' => '16.516300'
    'AnnualSalesQuantityBase' => '63.0000'
    'AnnualSalesAmountIncludingVAT_LCY' => '1061.6900'
    'AnnualAmountPrimeCostLCY' => '934.9200'
    'Margin' => '126.7700'
    'CntWeekSale' => '33'
    'Trend' => '.9040'
    'NormTotal' => '36.0000'
    'NormOfAnalyst' => '8.0000'
    'UoM' => 'К-Т'
    'UnitsPerParcel' => '1.00000000000000000000'
    'OptimumMultipleness' => '1.00000000000000000000'
    'QtyPerCar' => '1'
    'FirstDate' => '2009-03-31'
    'LastDate' => '2017-04-26'
    'Unmarketable' => '0'
    'Discontinued' => '0'
    'BlockPurchase' => '0'
    'MinReservK1' => '2'
    'MinReservK2' => '2'
    'OnWay' => '0'
    'OrderQty' => '0'
    'Backorder' => '0'
    'Comment' => ''
    'Stock' => '23.0000'
]

但是,当我在MS SQL Management Studio中运行查询时,列名称会正确呈现。

查询:

SELECT 
                          [ItemKey]
                          ,[ItemNo]
                          ,[CompanyKey]
                          ,[Description]
                          ,[SearchDescription]
                          ,[TopCode]
                          ,[ResponsibleBrandAnalyst]
                          ,[ResponsibleBrandManager]
                          ,[Grp]
                          ,[SubGrp]
                          ,[Brand]
                          ,[V00214] , [ПТО0004]
                          ,[PrimeCost]
                          ,[UnitPriceD3]
                          ,[AnnualSalesQuantityBase]
                          ,[AnnualSalesAmountIncludingVAT_LCY]
                          ,[AnnualAmountPrimeCostLCY]
                          ,[Margin]
                          ,[CntWeekSale]
                          ,[Trend]
                          ,[NormTotal]
                          ,[NormOfAnalyst]
                          ,[UoM]
                          ,[UnitsPerParcel]
                          ,[OptimumMultipleness]
                          ,[QtyPerCar]
                          ,[FirstDate]
                          ,[LastDate]
                          ,[Unmarketable]
                          ,[Discontinued]
                          ,[BlockPurchase]
                          ,[MinReservK1]
                          ,[MinReservK2]
                          ,[OnWay]
                          ,[OrderQty]
                          ,[Backorder]
                          ,[Comment]
                          ,[Stock]

                    FROM 
                    (
                    SELECT [ItemKey]
                          ,i.[ItemNo]
                          ,i.[CompanyKey]
                          ,[Description]
                          ,[SearchDescription]
                          ,[TopCode]
                          ,i.[ResponsibleBrandAnalyst]
                          ,i.[ResponsibleBrandManager]
                          ,[Grp]
                          ,[SubGrp]
                          ,[Brand]
                          ,[p].[VendorNo]
                          ,[PrimeCost]
                          ,[UnitPriceD3]
                          ,[DirectBaseUnitCostEUR]
                          ,[AnnualSalesQuantityBase]
                          ,[AnnualSalesAmountIncludingVAT_LCY]
                          ,[AnnualAmountPrimeCostLCY]
                          ,[Margin]
                          ,[CntWeekSale]
                          ,[Trend]
                          ,[NormTotal]
                          ,[NormOfAnalyst]
                          ,[UoM]
                          ,[UnitsPerParcel]
                          ,[OptimumMultipleness]
                          ,[QtyPerCar]
                          ,[FirstDate]
                          ,[LastDate]
                          ,[Unmarketable]
                          ,[Discontinued]
                          ,[BlockPurchase]
                          ,[MinReservK1]
                          ,[MinReservK2]
                          ,[OnWay]
                          ,[OrderQty]
                          ,[Backorder]
                          ,[Comment]
                          ,[Stock] 
                    FROM [PM_Item] [i] 
                    INNER JOIN [PurchPrice] [p] ON p.ItemNo = i.ItemNo AND p.CompanyKey = i.CompanyKey 
                    WHERE i.ResponsibleBrandAnalyst = 'EES0947' AND i.Brand = 'BOSCH'
                    ) AS SourceTable
                    PIVOT
                    (
                     MAX([SourceTable].[DirectBaseUnitCostEUR])
                     FOR [SourceTable].[VendorNo] IN ( [V00214], [ПТО0004])
                    )  AS PivotTable

[ПТО0004]列编码错误。

1 个答案:

答案 0 :(得分:0)

不幸的是,像您一样声明字符编码通常只会影响数据,而不会影响列名。您使用的是什么版本的驱动程序?这是known bug,已在今年早些时候发布的4.1.5中修复。