Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SP won't execute

Status
Not open for further replies.

lhatwwp

Technical User
Oct 23, 2007
79
US
Hello,

When I attempt to execute a stored procedure from PHP it doesn't work. The SP does work... so I'm guessing it has something to do with my bind statement. Any suggestions to get this code working?

TIA,
Lou


Code:
$RecDate=$_POST['RecalcDate'];

$db = mssql_connect("****","sa",*****) or die("Unable to connect to server");
mssql_select_db("Reporting");

$proc = mssql_init("CalculateDailyTotals", $db);

mssql_bind($proc,"@RequestDate",$RecDate,SQLDATETIMN);

mssql_execute($proc);
 
i'm not familiar with mssql but the manual says that the type parameter must be
type

One of: SQLTEXT, SQLVARCHAR, SQLCHAR, SQLINT1, SQLINT2, SQLINT4, SQLBIT, SQLFLT4, SQLFLT8, SQLFLTN.

and I note that the constant you are using is not one of these.
 
Thanks,

I read that too... I tried every type possible and still the procedure fails.

For giggles I wrote a procedure that doesn't take a parameter... it worked fine. So I know the problem is somewhere in the bind statement.

Lou
 
After doing some reading It seems MSSQL_Bind wasn't designed to handle dates.

There is a suggestion to pass the date as a string and then in the stored procedure convert it to a datetime format. I have tried that and I'm still not able to get this working.

Here's my PHP code so far
Code:
$RecDate=$_POST['RecalcDate'];

$db = mssql_connect("SQLServer","user","password") or die("Unable to connect to server");
mssql_select_db("Reports");

$proc = mssql_init("CalculateDailyTotals", $db);

mssql_bind($proc,"@RequestDate",$RecDate,SQLVARCHAR, false, null,19);

$Result = mssql_execute($proc);

My stored procedure looks like this

Code:
[dbo].[CalculateDailyTotals]
 (@RequestDate as datetime = NULL) 
AS 
SELECT @RequestDate = cast(@RequestDate as datetime)
SET @RequestDate = isnull(@RequestDate,CONVERT(CHAR(10), GetDate()-1, 120))

Can anyone see something wrong with my code? Any suggestions to allow execution of the sp from PHP?

TIA,
Lou
 
After reading other posts I tried a different approach to executing the stored procedure. This still isn't working... but maybe someone will see a problem I don't see.

Code:
$RecDate = date("Y-m-d",strtotime($_POST['RecalcDate'])); 


$db = mssql_connect("SQLServer","UserID","Pazzword") or die("Unable to connect to server");
mssql_select_db("Reporting");

$query = "EXECUTE Reporting.dbo.CalculateDailyTotals @RequestDate= '". $RecDate."'";

$Result= mssql_query($query);


if ($Result == 1){
echo "Success";
} ELSE {
echo "Failure";
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top