//先在application/config/database.php文件中配置好数据库用户名密码等 $this->load->database(); $query = $this->db->query('SELECT * FROM test'); //对象形式返回结果 foreach ($query->result() as $row) { echo $row->id . ' '; echo $row->content . '<br><br>'; } echo '查询结果数: ' . $query->num_rows(); $query = $this->db->query('SELECT * FROM test'); //数组形式返回结果 foreach ($query->result_array() as $row) { echo $row['id'] . ' '; echo $row['content'] . '<br><br>'; } echo '查询结果数: ' . $query->num_rows();