当前位置: 动力学知识库 > 问答 > 编程问答 >

php - How to solve 'Fatal error: Call to undefined method mysqli_stmt::fetchAll'?

问题描述:

I followed a tutorial about taking students attendance. But, it doesn't give results that should be done. Instead, it gives me this:

Fatal error: Call to undefined method mysqli_stmt::fetchAll() in C:\xampp\htdocs\ah\includes\functions.php on line 62

This is where the fetchAll is located:

function get_all_std($conn,$table,$limit){

try {

$query = "SELECT * FROM {$table} ORDER BY std_roll_no LIMIT {$limit}";

$stmt = $conn->prepare( $query );

$stmt->execute();

return $stmt->fetchAll();

} catch (Exception $e) {

return "ERROR". $e->getMessage();

}

}

And this is where the function get_all_std :

<?php

$view = $db->get_all_std($conn,'student_table',10);

foreach ($view as $post) {

$std_id = $post['std_roll_no'];

echo '<tr>';

// echo '<td>'. $post['student_id'] . '</td>';

echo '<td>'. $post['student_name'] . '</td>';

echo '<td>'. $post['dob'] . '</td>';

echo '<td>'. $post['gender'] . '</td>';

echo '<td>'. $post['email'] . '</td>';

echo '<td>'. $post['phone'] . '</td>';

echo '<td>'. $post['address'] . '</td>';

echo '<td>'. $post['Session'] . '</td>';

echo '<td>'. $post['Program'] . '</td>';

echo '<td>'. $post['Semester'] . '</td>';

echo '<td width=250>';

echo "<div class='ui mini buttons'>";

echo '<a class="ui mini positive button" href="student_update.php?std_roll_no='.$post['std_roll_no'].'"> <i class="glyphicon glyphicon-pencil"></i>Update</a>';

echo "<div class='or'></div>";

echo '<a class="ui mini red button" href="student.php?std_roll_no='.$post['std_roll_no'].'"><i class="glyphicon glyphicon-remove"> </i>Delete</a>';

echo "</div>";

echo '</td>';

echo '</tr>';

}

?>

So I would like to know how to solve this, because I already researched in the internet but none can solve my problem.

Thanks.

网友答案:

It's okay. I already solved the problem. Instead from using the code sample that I given above.

I changed the code structure to:

 <?php        
        $count=1;
        $sel_query="Select * from student_table ORDER BY student_id;";
        $result = mysqli_query($con,$sel_query);
        while($row = mysqli_fetch_assoc($result)) {

      echo '<tr>';

        echo '<td>'. $row['student_ID'] . '</td>';
        echo '<td>'. $row['school_ID'] . '</td>';
        echo '<td>'. $row['student_name'] . '</td>';
        echo '<td>'. $row['student_class'] . '</td>';

        echo '<td width=250>';
        echo "<div class='ui mini buttons'>";
        echo '<a class="ui mini positive button" href="student_update.php?student_ID='.$row['student_ID'].'"> <i class="glyphicon glyphicon-pencil"></i>Update</a>';
        echo "<div class='or'></div>";    
        echo '<a class="ui mini red button" href="student.php?student_ID='.$row['student_ID'].'"><i class="glyphicon glyphicon-remove"> </i>Delete</a>';
        echo "</div>";
        echo '</td>';    
       echo '</tr>';  
        }
       ?>

Which means I didn't use the fetch_all function. And I changed $post to $row.

分享给朋友:
您可能感兴趣的文章:
随机阅读: