Php 如何解决';致命错误:调用未定义的方法mysqli_stmt::fetchAll';?
我听了一篇关于让学生出勤的教程。但是,它没有给出应该做的结果。相反,它给了我这个:Php 如何解决';致命错误:调用未定义的方法mysqli_stmt::fetchAll';?,php,Php,我听了一篇关于让学生出勤的教程。但是,它没有给出应该做的结果。相反,它给了我这个: 致命错误:在第62行的C:\xampp\htdocs\ah\includes\functions.php中调用未定义的方法mysqli_stmt::fetchAll() 这就是fetchAll的位置: function get_all_std($conn,$table,$limit){ try { $query = "SELECT * FROM {$table} ORDE
致命错误:在第62行的C:\xampp\htdocs\ah\includes\functions.php中调用未定义的方法mysqli_stmt::fetchAll()
这就是fetchAll
的位置:
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();
}
}
这就是函数
获取所有标准的地方:
<?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>';
}
?>
所以我想知道如何解决这个问题,因为我已经在互联网上进行了研究,但没有人能解决我的问题
谢谢。没关系。我已经解决了这个问题。而不是使用我上面给出的代码示例
我将代码结构更改为:
<?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>';
}
?>
这意味着我没有使用fetch\u all
功能。我把$post
改为$row
没关系。我已经解决了这个问题。而不是使用我上面给出的代码示例
我将代码结构更改为:
<?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>';
}
?>
这意味着我没有使用fetch\u all
功能。我将$post
更改为$row
使用fetch_all()
-fetchAll()
是该函数的PDO版本。不,我仍然得到相同的结果致命错误:调用未定义的方法mysqli_stmt::fetch_all()在C:\xampp\htdocs\ah\includes\functions.php第62行
中,仔细查看后:fetch_all()
是结果对象的一个方法,而不是语句本身。好的,你有什么建议来代替这种方式吗?使用fetch_all()
-fetchAll()
是该函数的PDO版本。不,仔细查看后,我仍然得到相同的结果:fetch\u all()
是result对象的一个方法,而不是语句本身。好的,你有什么建议来代替这种方法吗?