<?php
require 'config.php';
$db = new connect();
$students = $db->select("students","ORDER BY students_id ASC");
if( $students != null ){
foreach ($students as $student) {
$student['error'] = '';
$output[] = $student;
}}else{
$student['error'] = 'No students...';
$output[] = $student;
}
echo json_encode($output);
?>如果数据库是空的,我就会出错。注意:未定义变量:输出
发布于 2020-03-02 02:14:03
请确保首先将$output初始化为空数组,
$db = new connect();
$output = array();
$students = $db->select("students","ORDER BY students_id ASC");只有在运行foreach循环时,您的代码才会初始化$output,而如果没有来自数据库的结果,则不会进行初始化
https://stackoverflow.com/questions/60478214
复制相似问题