SQL server-Prozedur nicht zurückgeben Ausgabe in PHP

Ich versuche, eine SQL-Prozedur auszuführen und Werte in PHP zurückzugeben. Mein Code ist wie folgt:

<?PHP include "conn.php"; $myquery= "exec CR_Report @System='Automated Forms'"; $fetched=sqlsrv_query($conn,$myquery); if( $fetched === false ) { die( print_r( sqlsrv_errors(), true ));} while($res=sqlsrv_fetch_array($fetched,SQLSRV_FETCH_ASSOC)) { echo $res['ID']; } ?> 

Vorgehensweise:

 CREATE procedure [dbo].[CR_Report] @Department varchar(60) = Null, @System varchar(30) = Null, @Fromdate date = Null, @Todate date = Null AS IF @System is Null and @Fromdate is Null and @Todate is Null BEGIN Create table #Temp_ConfigRequest_Department ( ID int, Form_No varchar(25), App_Date smalldatetime, System varchar(30) ) delete #Temp_ConfigRequest_Department insert into #Temp_ConfigRequest_Department SELECT * FROM [SUAF].[dbo].[Config_Request] where Admin_Department = @Department select * from #Temp_ConfigRequest_Department DROP TABLE #Temp_ConfigRequest_Department end IF @Department is Null and @Fromdate is Null and @Todate is Null BEGIN Create table #Temp_ConfigRequest_System ( ID int, Form_No varchar(25), App_Date smalldatetime, System varchar(30) ) delete #Temp_ConfigRequest_System insert into #Temp_ConfigRequest_System SELECT * FROM [SUAF].[dbo].[Config_Request] where System = @System select * from #Temp_ConfigRequest_System DROP TABLE #Temp_ConfigRequest_System end IF @Department is NULL and @System is NULL BEGIN Create table #Temp_ConfigRequest_Date ( ID int, Form_No varchar(25), App_Date smalldatetime, System varchar(30) ) delete #Temp_ConfigRequest_Date insert into #Temp_ConfigRequest_Date SELECT * FROM [SUAF].[dbo].[Config_Request] where convert(date, App_Date, 103) Between @Fromdate and @Todate select * from #Temp_ConfigRequest_Date DROP TABLE #Temp_ConfigRequest_Date end IF @Department is not Null and @System is not Null and @Fromdate is not Null and @Todate is not Null BEGIN Create table #Temp_ConfigRequest_All ( ID int, Form_No varchar(25), App_Date smalldatetime, System varchar(30) ) delete #Temp_ConfigRequest_All insert into #Temp_ConfigRequest_All SELECT * FROM [SUAF].[dbo].[Config_Request] where convert(date, App_Date, 103) Between @Fromdate and @Todate and Admin_Department = @Department and System = @System select * from #Temp_ConfigRequest_All DROP TABLE #Temp_ConfigRequest_All end 

Es gibt keinen Wert zurück und auch keine Fehler werden im Fehlerprotokoll protokolliert. Ich habe versucht, die SQL-Abfrage in der database zu testing und es gibt datasatz zurück. Um die Verbindung zu testing, habe ich einen Code für eine andere Prozedur in derselben file geschrieben und es gibt Werte zurück. Der zweite Code ist wie folgt:

 <?PHP $myquery="exec Configuration_Request @IDtemp='4275'"; $fetched=sqlsrv_query($conn,$myquery) ; if( $fetched === false ) { die( print_r( sqlsrv_errors(), true ));} while($res=sqlsrv_fetch_array($fetched,SQLSRV_FETCH_ASSOC)) { echo $res['Form_No']; echo $res['Administrator']; } ?> 

Vorgehensweise:

 create procedure Configuration_Request (@IDtemp int) as begin select * from Config_Request where ID=@IDtemp end 

Wo ist das Problem? Warum gibt der 1. Code keine Werte zurück? Würde schätzen jede Hilfe / Vorschlag.

Du könntest diese Prozedur ggf. vereinfachen. Es wird das Gleiche tun, aber schneller, weil Sie nicht erstellen und fallen Temp-Tabellen, die keinen Zweck dienen.

 CREATE procedure [dbo].[CR_Report] @Department varchar(60) = Null, @System varchar(30) = Null, @Fromdate date = Null, @Todate date = Null AS IF @System is Null and @Fromdate is Null and @Todate is Null SELECT * FROM [SUAF].[dbo].[Config_Request] where Admin_Department = @Department IF @Department is Null and @Fromdate is Null and @Todate is Null SELECT * FROM [SUAF].[dbo].[Config_Request] where System = @System IF @Department is NULL and @System is NULL SELECT * FROM [SUAF].[dbo].[Config_Request] where convert(date, App_Date, 103) Between @Fromdate and @Todate IF @Department is not Null and @System is not Null and @Fromdate is not Null and @Todate is not Null SELECT * FROM [SUAF].[dbo].[Config_Request] where convert(date, App_Date, 103) Between @Fromdate and @Todate and Admin_Department = @Department and System = @System