Reputation: 21
How to call a SQL Server's stored procedure with 2 parameters in PDO.
For example in SQLServer's prompt:
EXEC Test 'arg1', 'arg2'
What is the next step in PHP with PDO?
Thanks in advance for your response.
Upvotes: 2
Views: 1511
Reputation: 219
To use muliple parameters, just use bindParam for each parameter, either with named parameters:
$query="EXEC test :arg1, :arg2";
$stmt->bindParam(":arg1",$first_variable);
$stmt->bindParam(":arg2", $second_variable);
$stmt->prepare($query);
$stmt->execute();
Another way is to directly hand the parameters to the execute()-method as an array:
$stmt->execute(array(":arg1"=>$first_variable,":arg2"=>$second_variable
You can also use question marks for all parameters in the query:
$query="EXEC test ?,?";
...
...
$stmt->bindParam(1, $first_variable);
$stmt->bindParam(2, $second_variable);
or directly inside the execute():
$stmt->execute(array($first_variable, $second_variable));
Upvotes: 1