PHP database models that synchronize with the database?

Django models are really cool because you define all your models / tables directly in the code and then synchronize them with the database. That way, when you upgrade to your production server, you simply run the migration / synchronization script, and you cannot forget to update any tables.

The project I'm currently working on is not Django or Python-based, it is written in PHP and all queries are written in direct SQL (without ORM). We have many databases that need to be updated every time we make changes. Now we basically copy and paste our SQL scripts and run them where they should be run, or if this is a big change, we can use a script. The problem is that sometimes we forget to include some SQL.

If we had a code-based solution, it would automatically turn on with our clicks, and we could not forget to run it. So ... I'm looking for a solution that will allow us to define all our models in PHP, but let's continue to write direct SQL without using ORM (the project is 10 years old, it would be too much work to implement ORM right now). It would be nice if he could convert our existing database into a PHP model too.

Are there existing solutions for this?

+6
source share
3 answers

I have not used a PHP-based system with the fantastic model support offered by Django, but this project looks promising: a Django-like PHP request interface

+2
source

You can use Doctrine2, I think. There is native SQL support http://www.doctrine-project.org/docs/orm/2.0/en/reference/native-sql.html

+2
source

Source: https://habr.com/ru/post/891035/


All Articles