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

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

felixkiss/database
==================

A simple wrapper around PDO

v0.4.0(12y ago)0621MITPHPPHP &gt;=5.4.0

Since Mar 31Pushed 12y ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (7)Used By (0)

felixkiss/database
==================

[](#felixkissdatabase)

[![Build Status](https://camo.githubusercontent.com/5cd1a4015526f6aa25fe871099e00e1b297cc02d6ed20976bc71417eb348290a/68747470733a2f2f7472617669732d63692e6f72672f66656c69786b6973732f64617461626173652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/felixkiss/database)

This project is a thin wrapper around the PDO class to allow cleaner and more concise code when working with databases in PHP.

It is not intended to be an ORM, but rather a better way to work with hand-written SQL statements.

Installation
============

[](#installation)

Install through composer:

```
$ composer require felixkiss/database:0.*

```

or edit `composer.json` directly:

```
{
  "require": {
    "felixkiss/database": "0.*"
  }
}
```

and run `composer update` afterwards.

Usage
=====

[](#usage)

To instantiate a `Database` instance:

```
require 'vendor/autoload.php';

use Felixkiss\Database\Database;

$pdo = new PDO('mysql:dbname=foo;host=127.0.0.1', 'foo', 'bar');
$db = new Database($pdo);
```

Executing SQL Statements
------------------------

[](#executing-sql-statements)

```
$db->execute('TRUNCATE some_table');
```

The `execute` method can be used to execute any prepared statement. It takes an optional array of parameters as the second argument.

SELECT
------

[](#select)

```
$user = $db->select('SELECT * FROM user');
foreach ($users as $user)
{
    // Do something ...
}
```

### With Numbered Parameters

[](#with-numbered-parameters)

```
$users = $db->select('SELECT * FROM user WHERE age BETWEEN ? AND ?', [20, 40]);
```

### With Named Parameters

[](#with-named-parameters)

```
$users = $db->select(
  'SELECT * FROM user WHERE age BETWEEN :young AND :old LIMIT 0, :limit', [
  ':young' => 20,
  ':old'   => 40,
  ':limit' => 10,
]);
```

### Get An Array Of One Column

[](#get-an-array-of-one-column)

```
$users = $db->lists('SELECT username FROM users');
```

This will return a flattened array like:

```
['felixkiss', 'foobar', ...]

```

### Get A Single Value

[](#get-a-single-value)

```
$count = $db->pluck('SELECT COUNT(*) FROM users');
```

Inserting Records
-----------------

[](#inserting-records)

```
$db->insert('users', [
    'username' => 'felixkiss',
    'location' => 'Vienna, Austria',
]);
```

Updating Records
----------------

[](#updating-records)

```
$db->update('users', [
  'location' => 'Toronto, Canada',
  ], 'WHERE username = ?', ["felixkiss"]
);
```

Different Connections For Read And Write Operations
---------------------------------------------------

[](#different-connections-for-read-and-write-operations)

Sometimes it can be useful, to specify separate connections for reads (SELECT) and writes (INSERT, UPDATE, DELETE), e.g. in a replicated environment.

```
$read = new PDO('mysql:dbname=foo;host=127.0.0.1', 'foo', 'bar');
$write = new PDO('mysql:dbname=foo;host=mirror.example.com', 'foo', 'bar');
$db = new Database($read, $write);
```

Other SQL statements (via `execute()`) will be called on the write connection by default, unless `$readOnly = true` is specified as the third parameter:

```
$db->execute('TRUNCATE users'); // runs on write connection
$db->execute('LOCK TABLE users WRITE', [], true); // runs on read connection
```

License
=======

[](#license)

MIT, see LICENSE.md

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

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.

###  Release Activity

Cadence

Every ~6 days

Total

6

Last Release

4398d ago

### Community

Maintainers

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

---

Top Contributors

[![livkiss](https://avatars.githubusercontent.com/u/256075?v=4)](https://github.com/livkiss "livkiss (20 commits)")

---

Tags

databasepdo

### Embed Badge

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

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

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k578.4M5.6k](/packages/doctrine-dbal)[ifsnop/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k5.5M69](/packages/ifsnop-mysqldump-php)[nette/database

💾 Nette Database: layer with a familiar PDO-like API but much more powerful. Building queries, advanced joins, drivers for MySQL, PostgreSQL, SQLite, MS SQL Server and Oracle.

5656.7M234](/packages/nette-database)[dibi/dibi

Dibi is Database Abstraction Library for PHP

5013.8M120](/packages/dibi-dibi)[aura/sqlquery

Object-oriented query builders for MySQL, Postgres, SQLite, and SQLServer; can be used with any database connection library.

4572.9M34](/packages/aura-sqlquery)[envms/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

925511.7k13](/packages/envms-fluentpdo)

PHPackages © 2026

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