D
D
Dmitry Bolshakov2019-02-04 17:42:35
PHP
Dmitry Bolshakov, 2019-02-04 17:42:35

[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

2 answer(s)
D
Demian Smith, 2019-02-04
@Flappy1488

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

M
Maksim Fedorov, 2019-02-04
@Maksclub

I would be grateful if there is a ready solution.
Desirable separate functions for Insert,updata,select,delete

https://github.com/illuminate/database
$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 question

Ask a Question

731 491 924 answers to any question