CodeIgniter Forums

Full Version: Loading Database result into Class
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

i know that it works cause I saw how it worked but i'm not sure how to reproduce.

The following code shows how i try to Load the result of the database select into the object "Users" so that i get as result only the id of the Database.

Someone a Idea how to do this?
PHP Code:

class Users {
    public function __construct()

    public $id;


home_model extends CI_Model
    private $db;

    public function __construct()
        $this->db $this->load->database('default');

    public function p(){
        $this->db $this->load->database('default'true);
        return $this->db->select('*')->get('auth_users')->custom_result_object(Users);

(10-23-2019, 05:56 PM)InsiteFX Wrote: [ -> ]Read:

CodeIgniter User Guide -> Generating Query Results -> Custom Result Objects

Yeah works partly how i want it.

Problem with this is if the field is not within the Class he return it anyway.
I want him to return only the fields within the Class
Sounds like you would need to write a custom select to do what you want,
just selecting the fields you need.