Let's say I want to make a shop's database where everything has (id,name,price) in a MySQL table.
I saw two solutions for this with classes.
- The first one is using an Item class. When it's __construct is called it reads the informations from the MySQL table depending on it's $id. It stores the price and the name in a private variable and then it returns them on getPrice () and getName () functions.
- The second one is using an ItemManager class. It's like the Item class but the __construct function is empty and each function has $id parameter ( and it read's only the needed information every time, but sends query each function call ). This ItemManager class is a global variable and only contructed once.
Which one is better/more beautiful/faster/.... ? Or this only depends on how many items do we want look after in the MySQL table ? I'm waiting for replies based on this problem and about in what cases are one of the solutions more effective.
I could write example if that explains the problem better...