PHPackages                             phpf/database - 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. phpf/database

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

phpf/database
=============

Phpf Database package

115PHP

Since Jan 31Pushed 11y ago1 watchersCompare

[ Source](https://github.com/phpf/Database)[ Packagist](https://packagist.org/packages/phpf/database)[ RSS](/packages/phpf-database/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Components-Database
===================

[](#components-database)

Database abstraction layer for PHP 5.3+ using PDO.

\###Requirements

- `PDO`
- `FluentPDO` (included)
- `Phpf\Util`

\##Basic Usage

First, initialize the database settings; the connection itself is lazy-loaded.

```
use Phpf\Database\Database;

Database::init(
	'db_name',
	'db_host',
	'db_user',
	'db_password',
	'db_table_prefix',
	'pdo_driver', // must be a valid PDO driver
);
```

#### Schemas

[](#schemas)

Table schemas represent a single database table. They allow models to validate data, such as columns and indexes.

Create and register your table schemas. Note that the Database is a singleton, accessible via `instance()`.

```
Database::instance()->registerSchema(
	new \Phpf\Database\Table\Schema(array(
		'table_basename' => 'user',
		'columns' => array(
			'id' => 'INT(10) NOT NULL AUTO_INCREMENT',
			'name' => 'VARCHAR(255) NOT NULL',
			'email' => 'VARCHAR(255) NOT NULL',
			'password' => 'VARCHAR(255) NOT NULL'
		),
		'primary_key' => 'id',
		'unique_keys' => array(
			'name' => 'name'
		),
		'keys' => array(
			'email' => 'email'
		),
	)
);
```

Install the tables using your favorite method, or use `\Phpf\Database\Sql\Writer`.

#### Models

[](#models)

Now we need to create a model (see `Orm\Model`). Models operate on a single table through its `Database\Table` object (created when a schema is registered). Models wrap around their Table objects to call corresponding Database methods.

Models must define the method `getTableBasename()`, which must return the table's base name (i.e. without a prefix). In this example, the user model would return `user`.

```
$cntrl = new UserModel();
$cntrl->getTableBasename(); // returns 'user'
$rows_affected = $cntrl->insert( array(
	'name' => 'This Guy',
	'email' => 'thisguy@gmail.com',
	'password' => 'gobbldygook'
) );

if ( 0 !== $rows_affected ){
        $new_user_id = $cntrl->select(array('name' => 'This Guy'), 'id');
}
```

Fluent
------

[](#fluent)

The Database object wraps FluentPDO, an excellent fluent interface for PDO. To use it, call `Database::instance()->fluent()`.

```
$db = Database::instance();
$fpdo = $db->fluent();

$fpdo->from('user')
	->where(array('email', 'someguy@gmail.com'))
	// etc...
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

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

Maintainers

![](https://www.gravatar.com/avatar/2b5b7d38d1408fa7abf81c2650415faa6d135c0725b5a25c5e52aefeac03c455?d=identicon)[wells5609](/maintainers/wells5609)

---

Top Contributors

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

### Embed Badge

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

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

###  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)
