MSSQL列命名描述在PHP中

时间:2014-06-23 19:07:13

标签: php sql-server

我有一个名为Description的字段的DB,设置为nvarchar(max)。我能够从表中检索每一个其他数据,但不是每次都会出现乱码。

$conn = odbc_connect( $connection_string, $user, $pass, SQL_CUR_USE_DRIVER) or die('Failed to connect<br/>');
$test_rep = $conn->query('SELECT [Description] FROM InvoiceBase WHERE InvoiceNumber = \'652021\'');
$test_row = odbc_fetch_array($test_rep);
echo $test_row['Description'];

这给了我输出:

D�D1ON�MN$1xNN

我认为这必须将列名作为保留字,但即使在该列上使用别名也会给出类似的结果。

为什么会发生这种情况的任何想法?

修改

根据建议,使用:

echo utf8_decode($test_row['Description']);

结果:

K?K1@O?N?$1?N?

EDIT2

这是此表上创建命令的一部分(为了节省空间,我删除了20个左右的列,但是在那里留下足够的空间来了解这与其他列的对比情况):

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[InvoiceBase](
    [InvoiceId] [uniqueidentifier] NOT NULL,
    [OpportunityId] [uniqueidentifier] NULL,
    [PriorityCode] [int] NULL,
    [SalesOrderId] [uniqueidentifier] NULL,
    [OwningBusinessUnit] [uniqueidentifier] NULL,
    [LastBackofficeSubmit] [datetime] NULL,
    [PriceLevelId] [uniqueidentifier] NULL,
    [InvoiceNumber] [nvarchar](100) NOT NULL,
    [Name] [nvarchar](300) NULL,
    [Description] [nvarchar](max) NULL,
    [DiscountAmount] [money] NULL,
    [FreightAmount] [money] NULL,
    [TotalAmount] [money] NULL,
    [CustomerIdYomiName] [nvarchar](4000) NULL,
 CONSTRAINT [cndx_PrimaryKey_Invoice] PRIMARY KEY CLUSTERED 
(
    [InvoiceId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY],
 CONSTRAINT [AK1_InvoiceBase] UNIQUE NONCLUSTERED 
(
    [OwningBusinessUnit] ASC,
    [InvoiceNumber] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

0 个答案:

没有答案