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);


    try {
    $sql = $pdo->prepare("EXEC [contractor].[sync_licence] (?)");
    $params = 5;
    $sql->bindParam(1, $params, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 4000);
    $results = $sql->fetchAll();
    } catch (PDOException $e) {
    echo 'An error occured: ' . $e->getMessage();

Can anybody help with where I am going wrong?




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

People are also looking for solutions to the problem: php - Retrieve information from session array in codeigniter


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.