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

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

philwaters/database
===================

Simple database interface with row iterator

0.1.0(9y ago)017MITPHP

Since Apr 22Pushed 9y ago1 watchersCompare

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

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

Database
========

[](#database)

Simple database interface with row iterator.

Examples
--------

[](#examples)

### Instantiation

[](#instantiation)

```
$database = new Database($connection);

```

### Query

[](#query)

To select a row from `table`.

```
$query =
    "SELECT col1
       FROM table
      WHERE id = :col2_value";
$params = array(
    "id" => 123
);
$rows = $database->query($query);

```

To insert a row into `table`.

```
$query =
    "INSERT INTO table
               ( col1 )
        VALUES ( :col1_value,
                 :col2_value )";
$params = array(
    "col1_value" => "foo",
    "col2_value" => "bar"
);
$database->query($query, $params);

```

### Truncating Tables

[](#truncating-tables)

To truncate `table`.

```
$database->truncate("table");

```

### Transactions

[](#transactions)

Using database transactions.

```
$database->beginTransaction();
$database->query(...);

if (isOK()) {
    $database->commit();
} else {
    $database->rollback();
}

```

### Renaming Tables

[](#renaming-tables)

Renaming `old_name` to `new_name`.

```
$database->renameTable("old_name", "new_name");

```

### Swapping Tables

[](#swapping-tables)

Swapping `table_working` with `table_live`. This can be useful when updating a working copy of a table then once complete swap it with the live table.

```
$database->swapTables("table_working", "table_live");

```

### Iterating Rows

[](#iterating-rows)

To iterate all selected rows using `foreach`.

```
$query =
    "SELECT a, b, c
       FROM table";
$rows = $database->query($query);

foreach ($rows as $row) {
    echo $row['a'];
}

```

### Get All Rows

[](#get-all-rows)

To get all rows as an array.

```
$rows = $database->query($query);

echo json_encode($rows->all);

```

### Row Count

[](#row-count)

To get the number of rows selected.

```
$rows = $database->query($query);

echo count($rows);

```

### Array Access

[](#array-access)

To access a specific row.

```
$rows = $database->query($query);

echo $row[7]['col'];

```

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

Unknown

Total

1

Last Release

3357d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/20259786?v=4)[Phil Waters](/maintainers/PhilWaters)[@PhilWaters](https://github.com/PhilWaters)

---

Top Contributors

[![PhilWaters](https://avatars.githubusercontent.com/u/20259786?v=4)](https://github.com/PhilWaters "PhilWaters (1 commits)")

---

Tags

databaseiterator

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[doctrine/dbal

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

9.7k605.0M6.5k](/packages/doctrine-dbal)[doctrine/orm

Object-Relational-Mapper for PHP

10.2k295.3M7.2k](/packages/doctrine-orm)[doctrine/doctrine-bundle

Symfony DoctrineBundle

4.8k249.9M4.0k](/packages/doctrine-doctrine-bundle)[doctrine/migrations

PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easily deploying changes to it. It is a very easy to use and a powerful tool.

4.8k217.3M518](/packages/doctrine-migrations)[doctrine/data-fixtures

Data Fixtures for all Doctrine Object Managers

2.9k143.6M571](/packages/doctrine-data-fixtures)[robmorgan/phinx

Phinx makes it ridiculously easy to manage the database migrations for your PHP app.

4.5k48.7M444](/packages/robmorgan-phinx)

PHPackages © 2026

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