PHPackages                             paraffin/paraffin - 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. paraffin/paraffin

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

paraffin/paraffin
=================

ORM without the crap

3171PHP

Since Mar 3Pushed 12y ago1 watchersCompare

[ Source](https://github.com/lysol/paraffin)[ Packagist](https://packagist.org/packages/paraffin/paraffin)[ RSS](/packages/paraffin-paraffin/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

PARAFFIN
--------

[](#paraffin)

Full-fledged ORM is a gnarly beast. This is a pretty simple library, that provides some work-alike features and a pattern for writing object-oriented database code. Joins, subqueries, and arbitrary queries are written within static methods which return instances of the surrounding class.

Only MySQL is supported at the moment, Postgres support coming someday.

Usage
-----

[](#usage)

Assume `some_table` is a table with the columns `id int`, `name varchar(128)`, and `active tinyint`.

```
class TheTable extends Paraffin {
    public static $id_name = 'id';  // this is also the default
    public static $table = 'the_table';
}

TheTable::setPDOConnString("mysql:host=localhost;dbname=some_db")

$someRow = TheTable::get(2);  // get record with id 2
$someRow->name = 'AnotherValue';
$someRow->save();

$anotherRow = TheTable::create(array(
    'name' => 'friend',
    'active' => 1
    ));

$anotherRow->delete();

$moreRecords = TheTable::getMany(array(1,2,3,4));

$allOfTheRecords = TheTable::all();

$people = TheTable::where(array('name' => 'person'));

$people[0]->update(array('name' => 'smart'));

```

Well that's nice. If you need to do more advanced logic, don't try to force some annoying construct onto it, just write SQL.

```
class AnotherTable extends Paraffin {
    public static $table = 'another_table';

    public static function smartPeople() {
        $dbh = static::getInstance();
        $sth = $dbh->prepare("SELECT * FROM `" . static::$table . "`" .
              " WHERE `type` = 'smart'");
        $sth->execute();
        return $sth->fetchAll();
    }

    public function makeYetAnother() {
		$sth = $this->dbh->prepare("UPDATE `" . static::$table . "`" .
  	  		" SET `type` = 'yet_another' WHERE `id` = :id");
		$sth->bindValue(':id', $this->id);
		$sth->execute();
	}

	public function friends() {
		return YetAnotherTable::where(array('another_id' => $this->id));
	}
}

class YetAnotherTable extends Paraffin {
	public static $table = 'yet_another_table';
}

```

Just write PDO for the rest. The best reference for this library is the library itself.

Caveats
-------

[](#caveats)

Because by default all PDO queries in class methods return instances of itself, in order to return arrays you'll need to set your fetch mode to FETCH\_ASSOC first:

```
public function howMany() {
    $sth = $this->dbh->prepare("SELECT count() FROM `" . static::$table . "`");
    $sth->execute();
    $sth->setFetchMode(PDO::FETCH_ASSOC);
    ...
}

```

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.1% 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

Maintainers

![](https://www.gravatar.com/avatar/d2b08b3c540a70fb31fb1142a56c7988b5fbddd0f0f96a6bdd84b82f5ad1739e?d=identicon)[lysol](/maintainers/lysol)

---

Top Contributors

[![lysol](https://avatars.githubusercontent.com/u/55573?v=4)](https://github.com/lysol "lysol (27 commits)")[![neckro](https://avatars.githubusercontent.com/u/897054?v=4)](https://github.com/neckro "neckro (2 commits)")

### Embed Badge

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

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k116.5M113](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[pgvector/pgvector

pgvector support for PHP

198628.3k10](/packages/pgvector-pgvector)

PHPackages © 2026

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