>我正在使用php和后端SQL Server 2005创建一个报告。 我编写了吹查询,这在SQL Server中运行良好,而在PHP中执行时出错。
$query = "select distinct t1.VisitDate,t1.ReceiptNo,t1.VisitorNo,p.PatientName,STUFF((
SELECT f.Particular + ', ' from CollectionPointTable t2,FeesTable f
where t1.ReceiptNo = t2.ReceiptNo and f.ID = t2.TestID
FOR XML PATH(''), TYPE).value('.', 'VARCHAR(MAX)') ,1,0,'') Tests , sum(t1.payment) as Amount
from CollectionPointTable t1,patientinformationtable p
where p.visitorno = t1.visitorno and convert(varchar(10),t1.VisitDate,103) = '$date'
group by t1.Receiptno,p.patientname,t1.VisitorNo,t1.VisitDate
order by ReceiptNo";
$stid = sqlsrv_query($conn, $query);
$Today_patient_list = sqlsrv_fetch_array($stid,SQLSRV_FETCH_ASSOC);
这是错误给出的错误
警告:sqlsrv_fetch_array() 期望参数 1 是资源,布尔值在第 65 行的 C:''wampnew''www''logs''viewTodaysCollection.php 中给出
Use the following code, it should work:
$query = "select distinct t1.VisitDate,t1.ReceiptNo,t1.VisitorNo,p.PatientName,STUFF((
SELECT f.Particular + ', ' from CollectionPointTable t2,FeesTable f
where t1.ReceiptNo = t2.ReceiptNo and f.ID = t2.TestID
FOR XML PATH(''), TYPE).value('.', 'VARCHAR(MAX)') ,1,0,'') Tests , sum(t1.payment) as Amount
from CollectionPointTable t1,patientinformationtable p
where p.visitorno = t1.visitorno and convert(varchar(10),t1.VisitDate,103) = '$date'
group by t1.Receiptno,p.patientname,t1.VisitorNo,t1.VisitDate
order by ReceiptNo";
$stid = sqlsrv_query($conn, $query);
$Today_patient_list = sqlsrv_fetch_array($stid);