Executing Microsoft SQL Server Stored Procedure from PHP on Linux
Learn how to setup, install and configure Apache and PHP on a Linux box to execute MS SQL stored procedures. This extensive article takes you through an in-depth look on how to achieve your ideal environment.
Executing Microsoft SQL Server Stored Procedure from PHP on Linux - Executing MS SQL Server Procedures from PHP (Page 8 of 9 )
On my Windows box (home2k), I use Microsoft SQL Server query analyzer to create the following stored procedure on pubs database (I will use this stored procedure on Sybase SQL Server with pubs2 database in my next article):
CREATE PROC sp_GetBooksByPrice @minPrice money, @maxPrice money, @lowestPricedBook varchar(100) OUTPUT, @highestPricedBook varchar(100) OUTPUT AS DECLARE @realminPrice money, @realmaxPrice money, @totalBooks int SELECT @realminPrice = min(price) FROM titles WHERE price >=@minPrice SELECT @realmaxPrice = max(price) FROM titles WHERE price <=@maxPrice SELECT @lowestPricedBook =title FROM titles WHERE price = @realminPrice SELECT @highestPricedBook =title FROM titles WHERE price = @realmaxPrice SELECT @totalBooks = COUNT(title) FROM titles WHERE price >= @minPrice AND price <= @maxPrice RETURN @totalBooks GO
On the Red Hat side, use an editor to create the following file called sp_test.php:
echo "<h2>There were $numBooks Books returned.</h2>"; echo "The lowest price book was: <b>$lowestPricedBook</b>.<br>"; echo "The highest price book was: <b>$highestPricedBook</b>."; ?>
Save the file in /usr/local/Apache2/htdocs, open your browser, and input http://localhost/sp_test.php in address bar. It is useful when you debug your PHP code with MS SQL Server.