0

I worked on some web based appications most times using zend framework. I noticed that it takes a lot of your time to model a database for all the data from the php code. I other words you have to do everything about data twice.

Is there an alternative to designing the databases and structures of tables by hand?

I just want to create a database and let something else care about mapping the structure from the php programming logic to the database.

danijar
  • 27,743
  • 34
  • 143
  • 257
  • 1
    What you're looking for is called an ORM: http://stackoverflow.com/questions/108699/good-php-orm-library – David May 29 '12 at 18:15
  • One thing to note is that you're not necessarily "doing everything twice." Object modeling and data persistence are two very different things. One represents the business logic and processes with information in motion, the other persists and maintains the data at rest. There are fundamental differences between object-oriented design and relational data design, and trying to fit one into the other's paradigms and structures limits your design. However, if your model is simple enough that you're just writing forms-over-data then a decent framework will do much of the work for you. – David May 29 '12 at 18:19

1 Answers1

1

Ah, you're looking for an Object Relational Mapper! These are common in many types of web applications today.

In regards to PHP, the best one I've came across is Doctrine:

Object relational mapper (ORM) for PHP that sits on top of a powerful database abstraction layer (DBAL). One of its key features is the option to write database queries in a proprietary object oriented SQL dialect called Doctrine Query Language (DQL), inspired by Hibernates HQL. This provides developers with a powerful alternative to SQL that maintains flexibility without requiring unnecessary code duplication.

mattytommo
  • 52,879
  • 15
  • 115
  • 143
  • Looks nice! Does an ORM handles e.g. creating tables and their structure by itself during development, even if I change something after some time? – danijar May 29 '12 at 18:26
  • @sharethis Some do yeah. Doctrine can generate object classes from an existing database and when you make the change to the Database, the change is recognised by Doctrine, no need for additional mapping :) – mattytommo May 29 '12 at 18:29