I was breaking my head towards to find a better ORM approach for my own written framework. I used, and was very happy with P.O.R.K., for quite long time but, as most of us, I was looking for something that could improve the speed of my projects. P.O.R.K. configuration is not hard at all, it is compound of a set of classes encapsulated in three files that allowed me to create models in sort of ActiveRecord style and was really, really good when I first started.

Now my projects are bigger, require a lot more of database analysis and those sometimes go up to 30 tables or more. That means that once analysed a project, I had to create those tables in the database, specify their fields and so on… you know.

I found my self into the lazyness mode and I was already thinking that it could be great to create a set of libraries that do not require any configuration files at all and could manipulate my databases in such a way that not only queries for data but also dynamically creates the tables for me if they do not exists. That could save me around one or two days of work I thought…

Before creating anything I ask mr ‘Google’ if there was something around that could match my concept (never reinvent the wheel) and OH MY… I found it, its name is RedBean and I have to say that is one of the greatest libraries that have ever came across.

How it works

Create a database

Include the required files to work with RedBean -one file: redbean.inc.php


include('mypathto/redbean.inc.php");

Access its core:

//Assemble a database connection string (DSN)
$dsn = "mysql:host=localhost;dbname=mydatabasename";

//Connect to database and fetch the toolbox; either with password
$toolbox = RedBean_Setup::kickstartDev($dsn, $username, $password);

Now, just for this example: creating one Bean


$rb = $toolbox->getRedBean();

// lets create one object that we didnt even declared anywhere :)
$post = $rb->dispense('post');

// set some variables -fields
$post->title = 'This is magic';
$post->created = date('Y-m-d');

// save newly created object to database (how come?)
$rb->store($post);

If we were to look onto our database, we will find now that a new table is created called ‘post’ and your bean has successfully saved its properties.

Of course, this is a silly example, in my case I am using redbean on a MVC ‘modified’ pattern (I don’t like the ‘View’ part as it is implemented in modern frameworks and for small projects I use my own approach). Please, have a look to its manual, trust me, it is worth a try.

From the deep of my heart, THANKS for such a great job to his developer mr (Gabor) de Mooij. At last, one EASY yet POWERFULL library for our projects that really help us saving developing time.