1

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

Zhorov
  • 28,486
  • 6
  • 27
  • 52
Linto P D
  • 8,839
  • 7
  • 30
  • 39

2 Answers2

3

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
  • 5,721
  • 6
  • 36
  • 44
  • I suspect so, as Linto says "sending an integer parameter to the stored procedure" – SamStephens Oct 15 '10 at 18:19
  • 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 Oct 15 '10 at 20:14
  • 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 Oct 15 '10 at 20:48
  • Thank you very much SamStephens .My problem is over – Linto P D Oct 15 '10 at 21:16
0

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

DECLARE MyProc (@orderID int OUTPUT) AS ...
bobs
  • 21,844
  • 12
  • 67
  • 78
  • 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 Oct 15 '10 at 18:23
  • 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 Oct 15 '10 at 18:56
  • 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 Oct 15 '10 at 20:16
  • 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 Oct 15 '10 at 21:18