简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM