我有这个PHP脚本应该添加到系统的新运行。每次我运行它时,它都会告诉我我的游标状态无效。我无法弄清楚为什么会出现这个错误。在进入下一个代码之前,我已经完成了我的closeCursor()调用。这是PHP脚本,它抛出第42行的错误(我CreatePersonalRun存储过程的执行命令):PHP PDO Microsoft SQL Server:SQLSTATE [24000]:[Microsoft] [ODBC驱动程序11对于SQL服务器] - 无效光标状态
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(?)' – Archish