Object oriented databasing - adampatterson/Dingo-Framework GitHub Wiki

What's That?

Object oriented databasing is a term we use to describe the process of querying the database in an object oriented fashion. This standardized method allows us to replace SQL and use a consistant interface to access any kind of database.

For example you could have built your application to work with MySQL, but your customer only has PostgreSQL. By using object oriented queries you would not have to go through and change the syntax of all your SQL queries to make your application work with PostgreSQL because the PostgreSQL database driver handles any inconsistancies between the two database types for you.

A Simple Database Query

Here is an example of a simple SELECT query:

// Get user form data (query cleans data for us)
$username = input::post('username');

// Select the table
$table = db('mytable');

// Query the database
$data = $table->select('user','=',$username);

The above works exactly the same as the following SQL SELECT:

// Get and clean user form data
$username = input::post('username');
$username = db::quote($username);

// Query the database
$data = db::query("SELECT * FROM `mytable` WHERE `user`=$username");

Notice that in the object-oriented databasing example the database driver cleans the user form data of any possible SQL Injections for us? That's another perk of doing things this way :)

You could also shorten the object-oriented example by choosing the table and running the query at the same time:

// Get user form data (query cleans data for us)
$username = input::post('username');

// Select the table and query the database
$data = db('mytable')->select('user','=',$username);