Hallo Guys,
I really need your help. I try to execute Stored Procedure from MSSQL Server 2000. This is the very first time for me, so i look up from the internet and i found example from this site : [url]http://www.devarticles.com/c/a/PHP/Executing-SQL-Server-Stored-Procedures-With-PHP/4/
the scripts are :
[B]– Create the Stored Procedures :
[COLOR=”Blue”]USE Northwind
GO
CREATE PROC sp_GetNumProdsByPrice
@minPrice MONEY,
@maxPrice MONEY,
@lowestPricedProduct VARCHAR(40) OUTPUT,
@highestPricedProduct VARCHAR(40) OUTPUT
AS
SELECT @lowestPricedProduct = (SELECT TOP 1 ProductName
FROM Products
WHERE UnitPrice >= @minPrice
ORDER BY UnitPrice ASC)
SELECT @highestPricedProduct = (SELECT TOP 1 ProductName
FROM Products
WHERE UnitPrice <= @maxPrice
ORDER BY UnitPrice DESC)
RETURN (SELECT COUNT(*) FROM Products WHERE UnitPrice >= @minPrice AND UnitPrice <= @maxPrice)
[B]– The PHP scripts are :
[COLOR=”Red”]<?php
$myServer = “localhost”;
$myUser = “sa”;
$myPass = “”;
$myDB = “Northwind”;
$s = @mssql_connect($myServer, $myUser, $myPass)
or die(“Couldn’t connect to SQL Server on $myServer”);
$d = @mssql_select_db($myDB, $s)
or die(“Couldn’t open database $myDB”);
$query = mssql_init(“sp_GetNumProdsByPrice”, $s);
$minPrice = 0.00;
$maxPrice = 35.00;
$lowProd = “”;
$highProd = “”;
$numProds = 0;
// Bind the parameters
mssql_bind($query, “@minPrice”, $minPrice, SQLFLT8);
mssql_bind($query, “@maxPrice”, $maxPrice, SQLFLT8);
mssql_bind($query, “@lowestPricedProduct”, &$lowProd, SQLVARCHAR, TRUE, FALSE, 40);
mssql_bind($query, “@highestPricedProduct”, &$highProd, SQLVARCHAR, TRUE, FALSE, 40);
// Bind the return value
mssql_bind($query, “RETVAL”, &$numProds, SQLINT2);
mssql_execute($query);
echo “<h2>There were $numProds products returned.</h2>”;
echo “The lowest priced product was $lowProd.<br>”;
echo “The highest priced product was $highProd.”;
?>
after i check on my browser, i found some errors message like this :
[B][COLOR=”Red”]Warning: mssql_execute(): message: Could not find stored procedure ‘sp_GetNumProdsByPrice’. (severity 16) in c:inetpubwwwrootprojectcis web versiontest.sp.php on line 44
Warning: mssql_execute(): stored procedure execution failed in c:inetpubwwwrootprojectcis web versiontest.sp.php on line 44
There were 0 products returned.
The lowest priced product was .
The highest priced product was .
Are there something wrong with the scripts or i need to add some library for php, for your information, i was able to connect PHP with MSSQL Server, there is no problem with the connection.
Please help me ?
And Thank You for Your Answer