phpsqlstored-proceduresview

Execute Stored Procedure in PHP not working


We are currently using this PHP code in order to query a view however, we want this to now execute a stored procedure.

$sMSSQLQuery = "SELECT * FROM [reporting].[dbo].Report_thereport_cc;";

$aResults = RunMSSQLQuery($sMSSQLQuery);

echo json_encode($aResults);

When we try and run the above against a stored procedure, we get a Database Query Error. What do we need to change in order for it to work?


Solution

  • If you execute a stored procedure, you must use the EXEC statement like this

    EXEC storedProcedure1
    

    I'm not sure when use with PHP, but try this

    $sMSSQLQuery = "EXEC [reporting].[dbo].Report_thereport_cc;";
    
    $aResults = RunMSSQLQuery($sMSSQLQuery);
    
    echo json_encode($aResults);