我正在創建一個從存盤程序中獲取資料的 php API,存盤程序在 Dbeaver 上運行良好(檢索帶有值的記錄),但我的 api 正在檢索空值而沒有任何錯誤。
這是我的api中的代碼
$sql="exec ERP_Tracking.dbo.GET_SECURITYBRIEF_DATA";
try{
$stmt = sqlsrv_query($connection_crm,$sql);
}
catch(exception $e)
{
$indi="from query exec";
$error=$e;
}
$serial_no=0;
try
{
while($row=sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC) && $serial_no<50) //remove this condition later
{
$srow=[
"S.NO"=>$serial_no,
"1"=>$row["DOC"], //DOC
"2"=>$row["[AGRN #]"], //AGRN #
"3"=>$row["[VEH REG #]"], //VEH_REG #
"4"=>$row["ENGINE"], //ENGINE
"5"=>$row["CHASIS"], //CHASIS
"6"=>$row["[CUSTOMER TYPE]"], //CUSTOMER_TYPE
"7"=>$row["[CUSTOMER NAME]"], //CUSTOMER_NAME
"8"=>$row["[FATHER NAME]"], //FATHER_NAME
];
array_push($row_array,$srow);
//array_push($row_array,"counter checking");
$serial_no =1;
}
}
catch(Exception $e)
{
$indi="from while";
$error=$e;
}
ob_start();
header('Content-type: application/json');
if($error!='no error')
{
//echo json_encode($error);
echo json_encode($indi);
}
else
{
echo json_encode($row_array);
}
header("Connection: close");
header("Content-length: " . (string)ob_get_length());
ob_end_flush();
die;
我已確保所有列名都是正確的,但我得到的回應如下:
回復:
[
{
"S.NO": 0,
"1": null,
"2": null,
"3": null,
"4": null,
"5": null,
"6": null,
"7": null,
"8": null,
"9": null,
"10": null,
"11": null,
"12": null,
"13": null,
"14": null,
"15": null,
"16": null,
"17": null,
"18": null,
"19": null,
"20": null,
"21": null,
"22": null,
"23": null,
"24": null,
"25": null,
"26": null,
"27": null,
"28": null,
"29": null,
"30": null,
"31": null,
"32": null,
"33": null,
"34": null,
"35": null,
"36": null,
"37": null,
"38": null,
"39": null,
"40": null,
"41": null,
"42": null
},
{
"S.NO": 1,
"1": null,
"2": null,
"3": null,
"4": null,
"5": null,
"6": null,
"7": null,
"8": null,
"9": null,
"10": null,
"11": null,
"12": null,
"13": null,
"14": null,
"15": null,
"16": null,
"17": null,
"18": null,
"19": null,
"20": null,
"21": null,
"22": null,
"23": null,
"24": null,
"25": null,
"26": null,
"27": null,
"28": null,
"29": null,
"30": null,
"31": null,
"32": null,
"33": null,
"34": null,
"35": null,
"36": null,
"37": null,
"38": null,
"39": null,
"40": null,
"41": null,
"42": null
},.......
請在這件事上給予我幫助
uj5u.com熱心網友回復:
您正在設定$row為布爾&&條件的結果,而不是正在獲取的行,因為&&它的優先級高于=.
要么將賦值放在括號中,使用低優先級and的代替,要么先測驗。后者的性能要好一些,因為您在讀取限制時不會進行額外的提取。&&$serial_no
while($serial_no<50 && $row=sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) //remove this condition later
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/451733.html
