Я понял это.Я открывал оператор связывания, а затем в функции ViewComment () открывал другой оператор связывания, чтобы получить дополнительную информацию из других таблиц.Исправление состояло в том, чтобы сохранить bindResults в массиве, который будет заполнен оператором while, а затем закрыть этот оператор связывания.Затем переберите количество результатов, которые выдает while, в цикле for, который вызывает ViewComment () с прамиторами, являющимися массивом из массива bindResults.
Код ниже.
function getComments($inPostID=null)
{
$commentArray = array();
$tempArray = array();
if (!empty($inPostID))
{
//echo " Get comments for the post with the postID of ". $inPostID;
$stmt = db::connect()->prepare("SELECT * FROM Comments WHERE postID = ? ORDER BY commentDate DESC");
$stmt->bind_param('i', $inPostID);
$stmt->execute();
$stmt->bind_result($commentID, $postID, $userID, $commentDate, $commentContent);
while($stmt->fetch())
{
$bindResults = array($commentID, $postID, $userID, $commentDate, $commentContent);
array_push($tempArray, $bindResults);
}
$stmt->close();
$total = count($tempArray);
for($i = 0; $i < $total; $i++)
{
$thisComment = new ViewComment($tempArray[$i][0], $tempArray[$i][1], $tempArray[$i][2], $tempArray[$i][3], $tempArray[$i][4]);
array_push($commentArray, $thisComment);
}
}
return $commentArray;
}