PHP定义对象类型来保存MySQL表数据?

PHP定义对象类型来保存MySQL表数据?,php,mysql,Php,Mysql,我基本上是试图从MySql数据库中检索一行,并将行数据存储在单个对象中,然后将其传递给我的视图。我不需要数组,而是需要将其存储为名为“User”的自定义数据对象 这就是我到目前为止所做的: public function GetUserData(){ $this->load->database(); $query = $this->db->query('SELECT * from eyebase.UserTable WHERE id=1');

我基本上是试图从MySql数据库中检索一行,并将行数据存储在单个对象中,然后将其传递给我的视图。我不需要数组,而是需要将其存储为名为“User”的自定义数据对象

这就是我到目前为止所做的:

public function GetUserData(){

    $this->load->database();
    $query = $this->db->query('SELECT * from eyebase.UserTable WHERE id=1');

    //I have already implemented an array. I need to replace this with an object
    $users= array();
    foreach ($query->result() as $row)
    {
           $users[] = $row;
    }

    //I need to replace the line below with the object I created, instead of the array
    return $users;
}

//This is the object I need to use
class User{
     public $id;
     public $name;
     public $description;
     public $picture;
}
非常简单,只需将行的列值(如id、Name、Description、Picture)存储在对象中并返回它,而不是像我已经实现的那样将它们存储在数组中。我该怎么做