调用未定义的方法 CI_DB_mysqli_result::results()

Pra*_*als 1 php codeigniter

我对 CodeIgniter 很陌生。我得到低于错误。有人可以帮我吗。我检查了 StackOverflow 上的各种答案,但没有一个对我有帮助。

An uncaught Exception was encountered

Type: Error

Message: Call to undefined method CI_DB_mysqli_result::results()

Filename: /Applications/XAMPP/xamppfiles/htdocs/CodeIgniter/application/controllers/Stud_controller.php

Line Number: 10

Backtrace:

File: /Applications/XAMPP/xamppfiles/htdocs/codeigniter/index.php
Line: 315
Function: require_once
Run Code Online (Sandbox Code Playgroud)

下面是控制器代码

<?php
Class Stud_controller extends CI_Controller{
    function __construct(){
        parent::__construct();
        $this->load->database();
    }

    public function index(){
        $query = $this->db->get("stud");
        $data['records'] = $query -> results();
        $this->load->view('Stud_view',$data);
    }
}
?>
Run Code Online (Sandbox Code Playgroud)

这是视图代码

<!DOCTYPE html> 
<html lang = "en">

   <head> 
      <meta charset = "utf-8"> 
      <title>Students Example</title> 
   </head>
   <body>
        <a href = "<?php echo base_url(); ?>
         index.php/stud/add_view">Add</a>
   </body>

</html>
Run Code Online (Sandbox Code Playgroud)

当前不使用来自控制器的数据。任何帮助将不胜感激。提前致谢。

San*_*etR 5

你应该使用这样的东西

$data['records'] = $query -> result_array();
Run Code Online (Sandbox Code Playgroud)