views:

20

answers:

2

I am trying to execute a stored procedure from php.

In the php code iam sending a integer parameter to the stored procedure

$orderId =824;
$result =mssql_bind($sp, "@orderID", $orderId, SQLINT1, true, false);

I getting an error

mssql_execute() [function.mssql-execute]: message: The formal parameter "@orderID" was not declared as an OUTPUT parameter, but the actual parameter passed in requested output. (severity 16)

Can any one say the reason please

A: 

You must create your stored procedure so that it indicates that the parameter as an OUTPUT variable.

DECLARE MyProc (@orderID int OUTPUT) AS ...
bobs
so do i need to create that particular stored proceedure in php code?i mean the stored proceedure from the sql server
Linto P D
No. If the stored procedure needs to have the @orderID parameter as an output parameter, you would alter it using the same technique/tool in which it was created. Are you expecting the stored procedure to send the @orderID value to your PHP code? If No, then you want to look at @SamStephens answer and leave the procedure unchanged.
bobs
i got everything working ,but one problem.When i sent small oderid(eg 1,225,100,596,..)it works but when i sent big order id eg(100303),it not giving output, eventhough there is records for this order.So i changed the type parameter of mssql_bind with all most all , then i will get the result with a warning "Warning: mssql_execute() [function.mssql-execute]: WARNING! Some character(s) could not be converted into client's character set. Unconverted bytes were changed to question marks ('?'). (severity 16)".Do you have any idea
Linto P D
Hi bobs , i got the answer for last question from SamStephens Thank you very much bobs for your interest too.My problem is over
Linto P D
+3  A: 

The document of mssql_bind gives the signature of it as:

bool mssql_bind  ( resource $stmt  , string $param_name  , mixed &$var  , int $type  [, bool $is_output = false  [, bool $is_null = false  [, int $maxlen = -1  ]]] )

So your problem is you're setting $is_output as true.

Use

$orderId =824;
$result =mssql_bind($sp, "@orderID", $orderId, SQLINT1, false, false);
SamStephens
+1 same issue, different approach. I bet yours is right.
bobs
I suspect so, as Linto says "sending an integer parameter to the stored procedure"
SamStephens
i got everything working ,but one problem.When i sent small oderid(eg 1,225,100,596,..)it works but when i sent big order id eg(100303),it not giving output, eventhough there is records for this order.So i changed the type parameter of mssql_bind with all most all , then i will get the result with a warning "Warning: mssql_execute() [function.mssql-execute]: WARNING! Some character(s) could not be converted into client's character set. Unconverted bytes were changed to question marks ('?'). (severity 16)".Do you have any idea
Linto P D
Your problem is the SQLINT1 data type. See http://php.net/manual/en/mssql.constants.php. SQLINT1 is a single byte, -128 to 127. Use SQLINT4 instead.
SamStephens
Thank you very much SamStephens .My problem is over
Linto P D