N
N
NastyaG2016-11-04 10:22:18
PHP
NastyaG, 2016-11-04 10:22:18

How to organize work with the database in php using the OOP approach?

Hello. The essence of the question is this: I have Employees with the fields name, date of birth, department, position, number of hours worked, rate, salary.

class Employeer{
    public $name;
    public $birthday;
    public $dep;
    public $pos;
    public $count_hour;
    public $cost_hour;
    public $salary;
}

And employees are stored in a DB.
How to organize the work with the database? I am still a beginner and do not quite understand what is the right solution.
Describe methods for working with the database directly in the Employeer class? For example add(), getAll(), delete() ?
Or do you need to create a separate class for this and then create an instance of this class in the employee class and pass data to it?
And yet, I have two different types of employee, differing in the method of payment. Two separate classes are created, each working with the database.
Tell me, please, how to do everything reasonably? Thank you very much in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dmitriy, 2016-11-04
@dmitriylanets

i prefer to use datamapper example1 and example2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question