Answer the question
In order to leave comments, you need to log in
[PHP] DataBase in OOP, what is the best way to write it?
Recently I started to dive into OOP in php...
The question arose, how best to write a DataBase in OOP, so that it is convenient and safe?
I would be grateful if there is a ready solution.
Desirable separate functions for Insert,updata,select,delete
Answer the question
In order to leave comments, you need to log in
All popular DB layer design patterns are briefly described here https://gist.github.com/codedokode/c4cbc4d7dc8e45ea074a
Choose the one you like and get high.
Try DataMapper. It's pretty easy to implement (you won't even need a lib, except maybe the standard PDO) and less than ActiveRecord encourages programmers to write shitty code. Well, it is much less heavy than a full-fledged ORM. For understanding and fixing OOP - that's it.
I just tried to look for examples in the Russian tyrnet, but I did not find anything sane. Try to google yourself for the sake of interest.
Here is a very detailed article in English https://www.sitepoint.com/integrating-the-data-mappers/
And the most, in my opinion, the best example is provided by the Japanese (do not be afraid of hieroglyphs, see the code): https://github.com/hirak/pdo-datamapper-example
I would be grateful if there is a ready solution.
Desirable separate functions for Insert,updata,select,delete
$results = Capsule::select('select * from users where id = ?', array(1));
or$users = Capsule::table('users')->where('votes', '>', 100)->get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question