I code as a hobby so i do not have a formal education on this topic so please excuse me for this question. I really have done a lot of research on this topic but wasnt able to get a clear answer.
what class structure should i choose for database acess in php?
class DatabaseObject and one child class per table as well as a class DatabaseObjectArray wich extends ArrayObject and allows loading multiple DatabaseObjects at once. (i need to be able to iterate over it with a foreach or similar) DatabaseObject has functions load() and store().
class Database and interface DatabaseObject where each table correlates to one class that implements the inteface. Database can be used to load either one object at a time or multiple ones in an array.
where should the sql be done?
if I choose option one i would have some duplicate code between DatabaseObject and DatabaseObjectArray so would it be better to make use an extended PDO class?
For example I want to have an array called $conditions as well as a addCondition($key, $value, $operator = '=') function so that i can first define the condtions and then load() the data into the object.(the sql query is assembled based on $conditions) Should I define these in DatabaseObject and DatabaseObjectArray independently or in an extension of PDO?
- or maybe i should define a trait called DatabaseAccess that would be used either in the table classes or in the two Base classes of option 1.