PHP5 database abstraction layer. Writing SQL by hand is fine craft, but often it's more convenient to juggle arrays, e.g. to dynamically add conditions. Using Dabble this is made easy, while still allowing you to write literal SQL where you need.
Dabble is an extension of PHP's native PDO
class, so should work with any
existing code seamlessly.
composer install --save monomelodies/dabble
Download or clone the library. Register the /path/to/dabble/src
for the
namespace prefix Dabble
in your autoloader.
Instantiate a Dabble database object using your credentials:
<?php
use Dabble\Adapter\Mysql;
$db = new Mysql($dsn, $user, $pass, $options);
The database type (e.g. mysql:
in the above example) is added to the $dsn
string by Dabble.
The actual connection is opened in a just-in-time manner; hence, feel free to define as many Dabble adapters as you like (e.g. large sites connecting to various databases depending on the route). Connections aren't opened until the adapter is actually used. This allows you to define all your adapters in a central place.
Dabble supports four 'main' types of queries: select
,
insert
, update
and
delete
. These have corresponding method names on the
Dabble\Adapter
object. They all follow a similar syntax where argument one is
the table name, and further arguments are arrays of key/value pairs.
There are also helper classes that these are actually a front for.
Of course, regular PDO methods are also available for fine-grained tuning.
-
Sure - as long as your library uses
PDO
. Dabble is simply an extension toPDO
, so you should be good to go. -
It's a sort-of portmanteau of "database abstraction layer". And it sounded cute :)
-
Some of code dates back 10 years. Dabble is based on the database abstraction layer shipped in the Monolyth framework up to version 5. This in turn is based on code lifted from CU2 which Marijn's company owned from 2009 to 2014.
So yes, it's pretty well tested in the real world :)