当某些行包含空值时,PHP SQLSRV返回空白数据

时间:2018-07-05 22:48:41

标签: php sql-server php-5.6 sqlsrv

从PHP运行以下内容时,结果不正确:

$tsql = "select t1.ROLENAME as RN, t1.RID as RID, t1.APPLICATION as APL, (CASE when t2.ROLEID IS NULL then 'N' else 'Y' end) as LNKD from (Select r.name as ROLENAME, r.ID as RID, a.Name as APPLICATION from dbo.VSSRoles r left join dbo.VSSApplications a on r.ApplicationID = a.ID) t1 left join (select ROLEID from dbo.VSSPivotGroupsToRoles where GroupID = ?) t2 on t1.RID = t2.ROLEID order by t1.APPLICATION, t1.RID"

结果显示为:

Array
(
    [RN] => DefaultAdmin
    [RID] => 8
    [APL] => admin
    [LNKD] => Y
)
Array
(
    [RN] => DefaultAdmin
    [RID] => 5
    [APL] => api
    [LNKD] => Y
)
Array
(
    [RN] => DefaultAdmin
    [RID] => 6
    [APL] => kron
    [LNKD] => Y
)
Array
(
    [RN] => DefaultAdmin
    [RID] => 1
    [APL] => network
    [LNKD] => Y
)
Array
(
    [RN] =>                         
    [RID] => 0
    [APL] => 
    [LNKD] =>  
)
Array
(
    [RN] => DefaultAdmin
    [RID] => 7
    [APL] => opex
    [LNKD] => Y
)
Array
(
    [RN] => DefaultAdmin
    [RID] => 3
    [APL] => security
    [LNKD] => Y
)
Array
(
    [RN] =>                         
    [RID] => 0
    [APL] => 
    [LNKD] =>  
)
Array
(
    [RN] => DefaultAdmin
    [RID] => 4
    [APL] => telecom
    [LNKD] => Y
)
Array
(
    [RN] => DefaultAdmin
    [RID] => 2
    [APL] => voip
    [LNKD] => Y
)
Array
(
    [RN] =>                         
    [RID] => 0
    [APL] => 
    [LNKD] =>  
)
Array
(
    [RN] =>                         
    [RID] => 0
    [APL] => 
    [LNKD] =>  
)

但是,如果直接在SQL Server上直接运行它,则会返回:

RN  RID APL LNKD
'DefaultAdmin'  '8' 'admin' 'Y'
'DefaultAdmin'  '5' 'api'   'Y'
'DefaultAdmin'  '6' 'kron'  'Y'
'DefaultAdmin'  '1' 'network'   'Y'
'TestRole'  '12'    'network'   'N'
'DefaultAdmin'  '7' 'opex'  'Y'
'DefaultAdmin'  '3' 'security'  'Y'
'URICyberSecurity'  '9' 'security'  'N'
'DefaultAdmin'  '4' 'telecom'   'Y'
'DefaultAdmin'  '2' 'voip'  'Y'
'URICCC'    '10'    'voip'  'N'
'BranchMgr' '11'    'voip'  'N'

您知道为什么带有Null的行(由CASE转换为N)显示不正确吗?

SQL小组认为这是一个PHP错误,但我找不到任何会导致它的错误。

如果它有助于打印行的代码是:

while($result = sqlsrv_fetch_array( $getSQL, SQLSRV_FETCH_ASSOC)) {
                    echo "<pre>";
                    print_r($result);
                    echo "</pre>";
}

任何想法都会有所帮助,我一直在用键盘敲打我的头

0 个答案:

没有答案