PHPackages                             dral/oodb - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. dral/oodb

ActiveLibrary[Database &amp; ORM](/categories/database)

dral/oodb
=========

Easy Object Oriented Database Handler, like mongoDB.

182[1 issues](https://github.com/dralletje/OODB/issues)PHP

Since Sep 13Pushed 11y ago1 watchersCompare

[ Source](https://github.com/dralletje/OODB)[ Packagist](https://packagist.org/packages/dral/oodb)[ RSS](/packages/dral-oodb/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Object Oriented Database
========================

[](#object-oriented-database)

Bored of all the semi object oriented database handlers in php,
and inspired by the fully object oriented working of mongoDB in nodejs, I made OODB.
It's not a real database, just a class to access them easily and in a readable way.

Creating the connection and the table
=====================================

[](#creating-the-connection-and-the-table)

You just import the OODB main class.
This will help you to import the database of the type you want to use.

```
include('OODB/OODB.php');
```

---

Now you are ready to instantiate the database handler.
In this example I'm connecting to a Mysql database. As of PHP 5.3 you can use

```
$database = OODB::mysql($host, $database, $user, $password);
```

But people with a lower PHP version should use

```
$database = OODB::get("mysql", $host, $database, $user, $password);
```

Note that creating the handler differs from creating a mysqli handler, which is

```
$database = new mysqli($host, $user, $password, $database); # just the order of arguments
```

---

After you created the handler, you can select a table in the database.

```
$table = $database->tablename;
```

Yes, it actually is that easy! But this is not even te most awesome part.

Getting, setting, deleting
==========================

[](#getting-setting-deleting)

This, is where the real power starts. Let's say we aready connected to the database, and chose a table as we did in the previous section and we have already set up an table with the following structure (You can't create tables with this wrapper yet)

  id (auto incement) firstname Lastname Age But, the table is empty! Let's add some info!

```
$table->insert(array(
  'firstname' => 'Markus',
  'lastname' => 'Persson',
  'Age' => 42
));
```

That's it! Now this info is inserted. There is no restriction in what order you add the arguments. Just use the name. The script automaticly sees 'id' is auto\_increment, so it won't give you an error. The script also prevents any form of mysql injections, by using bind\_param automaticly. When you try to insert a non existing column, it will give you an instructive error.

Now the table looks like this:

  id (auto incement) firstname Lastname Age   0 Markus Person 42 I now magically added some more:

  id (auto incement) firstname Lastname Age   0 Markus Person 42   1 Barrack Obama 51   2 Michiel Dral 16 Right, but what if I want to find the age of Markus Persson back! Let's see what we can do

```
$result = $table->find(array(
  'firstname' => 'Markus',
  'lastname' => 'Persson',
));

if(count($result) !=== 1) {
  die("None, or more than one found? Strange..");
}

$markus = $result[0];
echo "The age of ".$markus['firstname']." ".$markus['lastname']." is ".$markus['age'];
```

Easy as that! I know the $markus\['firstname'\] and lastname are a bit expendable, but I just want to show how all data get's into a clean, easy to use array.

Imagine you want to remove everybody older than 18 years old. That would be done like this:

```
/* Note how I use $database here again, it's for easier comparisons */
$table->delete(array(
  'age' => $database::gte(18)
));
```

Or without the $database variable, it works like mongodb

```
$table->delete(array(
  'age' => array('$gte' => 18)
));
```

Documentation
=============

[](#documentation)

Update: You can use update using

```
$table->update($where, $new);
```

So in the previous example, if I would like to set the age of everybody with the firstname "Markus" to 1337, I would do You can also update using

```
$table->update(array(
  'firstname' => 'Markus'
), array(
  'age' => 1337
));
```

I'm writing a [api reference](https://github.com/dralletje/OODB/wiki/Api-reference) soon :)

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

---

Top Contributors

[![dralletje](https://avatars.githubusercontent.com/u/767261?v=4)](https://github.com/dralletje "dralletje (36 commits)")

### Embed Badge

![Health badge](/badges/dral-oodb/health.svg)

```
[![Health](https://phpackages.com/badges/dral-oodb/health.svg)](https://phpackages.com/packages/dral-oodb)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
