【发布时间】:2016-09-14 03:46:22
【问题描述】:
我有这个 php 脚本,它应该向系统添加一个新的运行。每次我运行它时,它都会告诉我我的游标状态无效。我无法弄清楚为什么会发生此错误。在继续下一段代码之前,我已经调用了 closeCursor()。这是 php 脚本,它在第 42 行抛出错误(我的 CreatePersonalRun 存储过程的执行命令):
if (isset($emailAddress, $caloriesBurnt, $dateRecorded, $deleted, $endTime, $startTime, $runType, $routeId)) {
$getAthleteID = $dsn->prepare("{CALL sp_GetAthleteId(?)}");
$getAthleteID->bindParam(1, $emailAddress, PDO::PARAM_STR);
$getAthleteID->execute();
$athleteData = $getAthleteID->fetch(PDO::FETCH_ASSOC);
$athleteId = $athleteData["AthleteID"];
$getAthleteID->closeCursor();
$runType = 0;
$deleted = false;
if ($athleteId != null) {
$getAthleteID->closeCursor();
$addRun = $dsn->prepare("{CALL sp_CreatePersonalRun(?,?,?,?,?,?,?,?)}");
$addRun->bindValue(1, $athleteId);
$addRun->bindValue(2, $caloriesBurnt);
$addRun->bindValue(3, $dateRecorded);
$addRun->bindValue(4, $deleted);
$addRun->bindValue(5, $endTime);
$addRun->bindValue(6, $routeId);
$addRun->bindValue(7, $startTime);
$addRun->bindValue(8, $runType);
$addRun->execute(); //This is where the error is thrown
if ($addRun->rowCount() > 0) {
echo json_encode(array("code" => 100, "message" => "Run has been added to the system successfully!"));
} else {
echo json_encode(array("code" => 200, "message" => "Something went wrong with adding the run to the system"));
}
} else {
echo json_encode(array("code" => 200, "message" => "Athlete does not exist"));
}
我的 getAthleteId 存储过程的代码:
ALTER PROCEDURE [dbo].[sp_GetAthleteId]
@emailAddress nvarchar(400)
AS
SELECT * FROM Athlete WHERE EmailAddress = @emailAddress;
【问题讨论】:
-
sp_GetAthleteId(?)中的查询是什么
标签: php sql-server pdo