Q:

Right way? PHP Object for Database Entity

I'm struggling with this kind of issue and I can't find direct answer to my question through Google.
Let's say we have a table 'users' in the database and it has the following columns: id, username, password, real_name.
Then my problems starts after that.
I know we can make an independent class for that like:
class User
{
    private $_id;
    private $_username;
    private $_password;
    private $_real_name;

    // getters

    // setters
}

Now, should I add functions like fetchById on that class? I mean, is it a good practice?
public function fetchById($id)
{
    // validate param
    // query database
    // copy results to appropriate properties
}

Or should it be done by another class, like UserManager? Then for every result, we convert the array result to of that object? 
Also, where should I put functions like fetchUsers where it will fetch multiple users from the database? Functions which deals with multiple records of the same entity.
I am looking for code efficiency and performance.
I know 'some' ideas but I can't justify it. I need help.
I'm currently working with CodeIgniter but I think this problem is PHP OOP in general.

A:

For me personally, I have my models (objects that represent database tables) extend an abstractModel object that has the ID attirbute and shared static functions like fetchById(). This abstract model also has methods like save() which use the ID of the object to save. 
You don't have to have an 'id' field in the table, the id of the model just has to be one of the unique key fields in the table. 
Instead of fetchUsers() I have a generic loadAll() static function in the abstract class. Thus you could call Users::loadAll() to get all the models of your users. This means that most of your models can be interfaced with in the same way and reduces duplication of code. Of course if there are methods specific to the model, then you will need to define them in child model.

