Executing a SQL Server Stored Procedure with parameters using PDO in php
I seem to be having great difficulty in executing a ms sql server stored procedure that contains parameters, I am able to execute either simple select statements or stored procedures without parameters but as soon as I try to bind parameters i get the message :
"An error occured: SQLSTATE[HY000]: General error: 102 General SQL Server error: Check messages from the SQL Server [102] (severity 15) [(null)]"
code from php is:
$pdo = new PDO($dsn, $user, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
$sql = $pdo->prepare("EXEC [contractor].[sync_licence] (?)");
$params = 5;
$sql->bindParam(1, $params, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);
$sql->execute();
$results = $sql->fetchAll();
var_dump($results);
} catch (PDOException $e) {
echo 'An error occured: ' . $e->getMessage();
}
Can anybody help with where I am going wrong?
Answer
Solution:
For anybody interested I have found the issue with the above statement. The error message returned was basically pointing towards a syntax issue with the t-sql statement, in this case the problem was the () surrounding the ?, therefore by removing the () the procedure now works, hope this helps anybody having the same issue