我无法读取PHP MySqli上的存储过程的结果
在PHP上。它被称为这样。但它总是返回零num_rows
$stmt = null;
$stmt = $conn->prepare("CALL `insert_exam_schedule`(?,?,?,?,?,?,?,?);");
$stmt->bind_param('sssissss',$_SESSION['ID'], $_REQUEST['subjectCode'], $_REQUEST['sectionCodeFull'], $_REQUEST['dayId'], $startTime, $endTime, $_REQUEST['room'], $_REQUEST['proctorId']);
$stmt->execute();
#TEMPS
$iResult = $stmt->get_result();
#$returnRow = $iResult->fetch_row();
if ($iResult->num_rows > 0) {
while ($iRow = $iResult->fetch_assoc()) {
$resultArray[] = $iRow;
}
$json['sucess'] = true;
$json['result'] = $resultArray;
echo json_encode($json);
}
else{
#resulted nothing
$json['sucess'] = false;
$json['result'] = "Failed: " . $iResult->num_rows . " : " . $stmt->affected_rows;
echo json_encode($json);
}
这是SQL Stores Procedure .. It Inserts然后选择select上的那个是我期望返回的内容但是它表明它没有返回或者我使用错误的方式来获取值。
CREATE DEFINER=`root`@`localhost` PROCEDURE `insert_exam_schedule`(`uId` VARCHAR(32),
`iSubjectCode` VARCHAR(16),
`iSectionCodeFull` VARCHAR(3),
`iDayId` INT(10) UNSIGNED,
`iStart` TIME,
`iEnd` TIME,
`iRoom` VARCHAR(32),
`iProctorId` VARCHAR(32))
#VALIDATE SECTION SUBJECT COMBINATION
#check if start is less than end
#CHECK IF ROOM IS AVAILABLE AT TIME
#CHECK IF PROCTOR IS AVAILABLE AT TIME
#CHECK IF CLASS IS ALREADY SCHEDULED
#CHECK IF USER ENTERED IS A PROCTOR FOR REDUNDANCY
DECLARE time_a, time_b TIME DEFAULT NULL;
DECLARE done INT DEFAULT FALSE;
DECLARE room_cursor CURSOR FOR (SELECT `Start`, `End` FROM `exam_schedules` WHERE `Room` = `iRoom` AND `Day Id` = `iDayId`);
DECLARE proc_cursor CURSOR FOR (SELECT `Start`, `End` FROM `exam_schedules` WHERE `Proctor Id` = `iProctorId` AND `Day Id` = `iDayId`);
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
#-------------------------------
SET @classId = (
SELECT `classes`.`Id` FROM `classes`
JOIN `subjects` ON `classes`.`Subject Id` = `subjects`.`Id`
WHERE `Section Code Full` = `iSectionCodeFull` AND `subjects`.`Code` = `iSubjectCode`);
#VALIDATE SECTION SUBJECT COMBINATION
#must be 1
SET @classValid = (
SELECT COUNT(`classes`.`Id`)
FROM `classes`
JOIN `subjects` ON `classes`.`Subject Id` = `subjects`.`Id`
WHERE
`subjects`.`Code` = `iSubjectCode` AND
`classes`.`Section Code Full` = `iSectionCodeFull`);
#check if start is less than end
#must be >= 60
SET @timeDiff = (SELECT TIME_TO_SEC(TIMEDIFF(`iEnd`, `iStart`)) / 60);
#CHECK IF ROOM IS AVAILABLE AT TIME
#must be false
SET @roomHit = FALSE;
#set @roomTimeConflict = (SELECT COUNT(`Id`) FROM `exam_schedules`
# WHERE `Room` = '206' AND (`Start` < '00:02:00' AND `End` > '01:00:00'));
OPEN room_cursor;
room_looper: LOOP
FETCH room_cursor INTO time_a, time_b;
IF done THEN
LEAVE room_looper;
END IF;
IF (time_a < `iEnd` AND time_b > `iStart`) THEN
SET @roomHit = TRUE;
LEAVE room_looper;
END IF;
END LOOP;
#CHECK IF PROCTOR IS AVAILABLE AT TIME
#must be 0
SET @procHit = FALSE;
#set @proctorTimeConflict = (SELECT COUNT(`Id`) FROM `exam_schedules`
# WHERE `Proctor Id` = '1010338' AND (`Start` < '01:00:00' AND `End` > '00:00:00'));
OPEN proc_cursor;
SET done = FALSE;
proc_looper: LOOP
FETCH proc_cursor INTO time_a, time_b;
IF done THEN
LEAVE proc_looper;
END IF;
IF (time_a < `iEnd` AND time_b > `iStart`) THEN
SET @procHit = TRUE;
LEAVE proc_looper;
END IF;
END LOOP;
#CHECK IF CLASS IS ALREADY SCHEDULED
#must be 0
SET @classHit = (SELECT COUNT(`Class Id`) FROM `exam_schedules` WHERE `Class Id` = @classId);
#CHECK IF USER ENTERED IS A PROCTOR (x)
#must be 1
SET @validProf = (SELECT COUNT(`Id Number`) FROM `users` WHERE `Id Number` = `iProctorId` AND `Access Id` = 2);
#SELECT @classValid, @timeDiff, @roomHit, @procHit, @classHit, @validProf;
#-----------
IF (@classValid = 1 AND @timeDiff >= 60 AND @roomHit = FALSE AND @procHit = FALSE AND @classHit = 0 AND @validProf = 1) THEN
INSERT INTO `db_main`.`exam_schedules`(
`Class Id`,
`Day Id`,
`Start`,
`End`,
`Room`,
`Proctor Id`
)
VALUES(
@classId,
`iDayId`,
`iStart`,
`iEnd`,
`iRoom`,
`iProctorId`
);
IF (ROW_COUNT() != 0) THEN
SET @rank = 0;
SET @subject = (SELECT `subjects`.`Code` FROM `classes` JOIN `subjects` ON `classes`.`Subject Id` = `subjects`.`Id` WHERE `Section Code Full` = `iSectionCodeFull`);
SET @examDay = (SELECT `rank` FROM (SELECT @rank:=@rank+1 AS `rank`, `Id`, `Date` FROM `exam_dates` ORDER BY `Date` ASC) AS `datesRanked`
WHERE `Id` LIKE `iDayId`);
CALL `insert_logs`(`uId`,'1', CONCAT('Added schedule for ', @subject, ' ', `iSectionCodeFull`, ' on day ', @examDay, ' of examination.'));
END IF;
END IF;
SELECT @classValid AS `classValid`, @timeDiff AS `timeDiff`, @roomHit AS `roomHit`, @procHit AS `procHit`, @classHit AS `classHit`, @validProf AS `validProf`;