This can be a design problem I face regularly and Let me find some general experience regarding the subject. The code provided here's just a good example.

Within the design phase it's not hard to decide you'll need an item:

User
==========
Unique ID
Login name
Password
Full name

And it's not hard to convert it right into a database object:

CREATE TABLE user (
    user_id INT NOT NULL PRIMARY KEY,
    username VARCHAR(15) NOT NULL UNIQUE,
    password_hash CHAR(32) NOT NULL,
    full_name VARCHAR(50)
);

My doubts start at PHP level. The apparent conversion is:

<?php
class User{
    public $user_id, $username, $full_name;
}
?>

However, how must i fill in the values?

I'm able to keep your class DB-agnostic:

<?php
class User{
    public $user_id, $username, $full_name;
    public function __construct($user_id, $username, $full_name){
        $this->user_id = $user_id;
        $this->username = $username;
        $this->full_name = $full_name;
    }
}
?>

However I have to run the query elsewhere...

I'm able to encapsulate it within the class constructor:

<?php
class User{
    public $user_id, $username, $full_name;
    public function __construct($user_id){
        $sql = 'SELECT username, full_name FROM user WHERE user_id=?';
        $parameters = array($user_id);
        $res = get_row_from_db($sql, $parameters);

        $this->user_id = $user_id;
        $this->username = $res['username'];
        $this->full_name = $res['username'];
    }
}
?>

This looks elegant however it prevents me from doing plenty of stuff using the class:

  • Validate a person by account information ($user_id isn't known yet)
  • Print user info from forum posts (I can not afford 100 queries to exhibit 100 customers)

Probably, I have to define several classes but I am unsure concerning how to organise it. One base class and several child classes? Independent classes? Single class with specific techniques? Possibly it is a well-known design pattern however i was trained procedural programming.

I'd also appreciate ideas about:

  • Handling an accumulation of customers
  • Storing info in session so DB does not have to be queried on every page request

==== For That RECORDS====

I have labeled Gordon's reply as answer for this provides interesting reading through. Whatever, it's worth observing that I have found a very illustrative code snippet within the user comments within the Object Serialization page from the PHP manual that may be made clear the following:

  • It uses one class.
  • A case signifies a particular user.
  • The constructor is given using the user particulars.
  • The course provides static techniques for functionality that's needed before having a case, e.g. fetching a person from DB by ID or title.
  • User instances could be serialized as session data.

Not an OOP guru, I have thought it was quite simple yet neat and helpful. OOP texts possess a inclination to overcomplicate simple tasks and my daily work consists mainly in small projects.