简体   繁体   English

在php中使用PDO执行带有参数的SQL Server存储过程

[英]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 : 我似乎在执行包含参数的ms sql服务器存储过程时遇到很大的困难,我能够执行简单的select语句或不带参数的存储过程,但是一旦我尝试绑定参数,我就会收到消息:

"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: 来自php的代码是:

    $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 返回的错误消息基本上指向t-sql语句的语法问题,在这种情况下,问题是()周围的(),因此通过删除()该过程现在可以正常工作,希望这可以帮助遇到相同问题的任何人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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