When you are using PDO
with MSSQL driver you actually use FreeTDS as low level driver. There is some different ways to execute stored procedures - language queries and RPC call.
FreeTDS also supports TDS protocol version 4.2 and 7.x. The one of main difference between them is a behaviour of stored procedure call. Microsoft changed the behaviour from protocol 4.2 to 7.0 not returning output parameters from language queries. Language queries mainly send the textual query to the server wrapping into a TDS packet.
$stmt = $dbh->prepare("CALL sp_takes_string_returns_string(?)"); $value = 'Hello!'; $stmt->bindParam(1, $value, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000); $stmt->execute(); print "The output is $value\n";
Actually you send something like "EXEC sp_takes....". And if you run sample above with MSSQL you would get empty output parameter in TDS 7.х and expected result with 4.2. Why we can`t use 4.2 and be happy? It has a lot of limitations:
prepared statements
) are not supported.So, the 4.2 is not a variant.
$stmt = mssql_init('sp_takes_string_returns_string'); $value = 'Hello!'; mssql_bind($stmt, 1, $value, SQLVARCHAR, true, false, 4000); mssql_execute($stmt); print "The output is $value\n";
Using sample above with native mssql extension in php you got right result with TDS 7.2. Actually you send binary RPC packet with that code.
Is there is any way to make RPC call for stored procedure with PDO and MSSQL driver?
You can use the return statement inside a stored procedure to return an integer status code (and only of integer type). By convention a return value of zero is used for success. If no return is explicitly set, then the stored procedure returns zero. You should use the return value for status codes only.
The Output Parameters in Stored Procedures are used to return some value or values. A Stored Procedure can have any number of output parameters. The simple logic is this — If you want to return 1 value then use 1 output parameter, for returning 5 values use 5 output parameters, for 10 use 10, and so on.
You can't use OUTPUT parameters with a user defined function (UDF). By definition a scalar function just returns one scalar value. You have two options: 1 - Make this a stored procedure using OUTPUT parameters.
Either I missed FreeTDS when I first answered, or this question was updated. Either way...
FreeTDS Does not support output parameters in MSSQL Server 7 SP3 or greater. This is due to changes made in SQL Server.
---Old Response Below---
I know it's not exactly what you're looking for.
I ran through some old files to the only time I'd linked to MSSQL and pulled this.
$con = mssql_connect($db['host'], $db['user'], $db['pass']); mssql_select_db($db['database'], $con);//Select DB $result = mssql_query("my_Procedure_Name ".$propertyOne.", ".$propertyTwo."");
I hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With