My family hosts an event called the Chili Bowl once a year. All our friends bring over chili, we play football, then eat the chili.…and most importantly vote to see who brought the best chili and who brought the most original chili.
Counting up the votes can take a bit of time during the party. It’s certainly not as fun tallying votes as it is socializing, so I got it in my head to write a mobile app to take care that bit of paperwork for us. Of course I spent a lot longer writing the app than we would ever spend counting votes by hand, but it was a fun project and I learned a few things.
One of the open source tools that I leveraged for the back end was the RedBeanPHP ORM. An ORM is a library or toolkit that performs Object Relational Mapping. ORMs make it easy for developers to read and write objects to a traditional relational database.
My Chili Voting app needed a very small back end running on a web server. It wouldn’t have to be maintained by anyone, it wasn’t going to get much in the way of advanced planning, and it wasn’t going to become a large project. This one of the types of project where PHP is a great choice.
I’ve used a number of ORMs in the past and, for me at least, they can save a lot of time if your use cases match up with the design of the ORM. But I didn’t want to spend a lot of time configuring frameworks or installing libraries. I also didn’t want to learn a new syntax for defining my object <-> data mapping. That’s where RedBean really excelled.
Unlike ORMs I’ve used in C# or Java, RedBean didn’t need any configuration. You created objects and then called save() on them. RedBean would then persist them in the database. You didn’t need to write a XML configuration file to define the mapping, you didn’t need to use a VisualStudio Wizard, you didn’t even need to create the database tables in advance. I started with a blank database and as the software was developed, all the tables and db columns I needed were created automatically for me. It was a wonderful time saver. Even the library didn’t need any real installation. I just dropped a single file in my includes directory and it was done.
Of course I wouldn’t recommend developing this way for your enterprise critical application or your million visits a day web site. For me though, with a budget of 0 dollars and an estimated user base of 35 people, it was perfect. If you have a small project or want to put together a prototype or proof of concept application, I highly recommend it.
One response to “Lightweight ORM for PHP”
Is there a good object-relational-mapping library for PHP?