Ahoy,
I'm having a bit of trouble executing a stored procedure using PHP's SQLSRV package thing. It's pretty much just a simple select query, with the parameters being passed through a php (it's from a property search).
SqlSrv is a tough nut to crack as docuemtnation is either non existent, or there are a various different methods on how to execute a Stored Procedure.
Here's the one I've gone with:
` $bedrooms = '3';
$pageno = '1';
$branchID = '1844';
$postcode = 'BL1';
$mint = '0';
$maxt = '1000000000';
$params = array(
array($bedrooms, SQLSRV_PARAM_IN),
array($mint, SQLSRV_PARAM_IN),
array($maxt, SQLSRV_PARAM_IN),
array($postcode, SQLSRV_PARAM_IN),
array($pageno, SQLSRV_PARAM_IN),
array($branchID, SQLSRV_PARAM_IN)
);
/* Execute the query. */
$stmt = sqlsrv_query($conn, '{CALL PROPERTY_SEARCH_S(?,?,?,?,?,?)}', $params);
if( $stmt === false )
{
echo "Error in executing statement 3.\n";
die( print_r( sqlsrv_errors(), true));
}
while($row = sqlsrv_fetch_array($stmt)){ `
I've temporarily created the parameters at the top and then, from what I gather, I'm supposed to plonk the params in an array with a constant to define what direction it's going in (I guess!, as setting it to OUT messes it up).
It then executes the search and then goes on to start a loop.
HOWEVER, I get the following error from it, which I don't quite understand:
Error in executing statement 3. Array ( [0] => Array ( [0] => 01000 [SQLSTATE] => 01000 [1] => 0 [code] => 0 [2] => [Microsoft][SQL Server Native Client 10.0][SQL Server] SELECT TOP 25 p.PriceText, ph.PHOTOURL, p.PropertyID, p.EstateAgentID, p.StreetAddress1, p.StreetAddress2, p.Description1, p.Town, p.Postcode, p.PriceText, p.Bedrooms, p.Kitchens, p.Bathrooms, p.Garage, p.Gardens, PT.PROPERTY_TYPE,0 AS PAGE_COUNT FROM dbo.PROPERTY P LEFT JOIN dbo.PROPERTY_PHOTOS PH ON P.PROPERTYID = PH.PROPERTYID AND PH.CATEGORY = 'PRIMARY' LEFT JOIN PROPERTY_TYPE PT ON P.PROPERTYTYPEID = PT.PROPERTY_TYPE_ID WHERE P.POSTCODE LIKE [message] => [Microsoft][SQL Server Native Client 10.0][SQL Server] SELECT TOP 25 p.PriceText, ph.PHOTOURL, p.PropertyID, p.EstateAgentID, p.StreetAddress1, p.StreetAddress2, p.Description1, p.Town, p.Postcode, p.PriceText, p.Bedrooms, p.Kitchens, p.Bathrooms, p.Garage, p.Gardens, PT.PROPERTY_TYPE,0 AS PAGE_COUNT FROM dbo.PROPERTY P LEFT JOIN dbo.PROPERTY_PHOTOS PH ON P.PROPERTYID = PH.PROPERTYID AND PH.CATEGORY = 'PRIMARY' LEFT JOIN PROPERTY_TYPE PT ON P.PROPERTYTYPEID = PT.PROPERTY_TYPE_ID WHERE P.POSTCODE LIKE ) )
I'm not 100% what its telling me here. My guess is that the params aren't being passed through, otherwise something would appear next to penultimate closing bracket. The "[message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]" might be a clue, although again I can't quite work it out!
The database guy I deal with tells me he's tested the stored procedure out on his end without error, so it must be the scripting side.
Your help would be much appreciated!
Thanks,
Tom