【发布时间】:2019-01-11 09:27:40
【问题描述】:
我需要一些关于 PHP PDO MSSQL 存储过程的帮助。
我有一个存储过程,它使用两个参数userId 和pwd 调用,然后存储过程返回两个值status 和token(在存储过程中使用SELECT @status as status, null as token 返回值)
当我尝试使用 PDO 从 PHP(7.0 版)调用存储过程时,我没有收到任何返回值
这是 PHP 代码:
$conn = new PDO("sqlsrv:server=".$host.";Database=".$db_name,
$username,$password);
$userId = "2465";
$pwd = "460";
$query = "exec sp_getToken @userId=:userId, @pwd=:pwd";
$stmt = $conn->prepare($query);
$stmt->bindValue(':userId', $userId);
$stmt->bindValue(':pwd', $pwd);
$stmt->execute();
while($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
var_dump($result);
}
谁能告诉我该怎么做?
【问题讨论】:
-
简单;你从未执行过查询。
-
它一定是在我有的副本中滑倒了 $stmt->execute();在最后一个 bindValue 和 while 循环之间
-
然后更新您的帖子并检查错误和日志。你没有这样做。
-
TBH,我不知道是什么导致您的代码无法正常工作。您能否检查php.net/manual/en/pdo.error-handling.php 和php.net/manual/en/function.error-reporting.php 的错误(设置为捕获和显示)以及尝试将
bindValue()更改为bindParam()的可能性。 -
您能否再次更新您的问题(请)关于架构是什么、列类型和示例值?它可能会在很多方面有所帮助。如果您觉得这无关紧要,请参阅下面的答案。
标签: php sql-server stored-procedures pdo