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

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

idct/database-comparator
========================

Datasource sets comparing framework

1.0.0(8y ago)099MITPHPPHP &gt;=5.3.0

Since Mar 10Pushed 8y ago2 watchersCompare

[ Source](https://github.com/bpacholek/database-comparator)[ Packagist](https://packagist.org/packages/idct/database-comparator)[ Docs](https://github.com/ideaconnect/database-comparator)[ RSS](/packages/idct-database-comparator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

database-comparator
===================

[](#database-comparator)

Basic framework for database comparisons. Allows to report differences between two datasources.

Useful especially when making a major change in an application which writes data to any data source and you would like to verify if nothing got broken. One could say that it allows to write easy black box tests.

contents
========

[](#contents)

Framework provides so far:

- `PdoSource`: for comparing databases to which PDO can be used as a connector.
- `SourceInterface`: interface for writing new compatible data source connectors.
- `SimpleOutput`: basic textual output for writing out differences to files.
- `OutputInterface`: interface for building new output writing objects.

usage
=====

[](#usage)

1. Install by composer using:

```
composer require idct/database-comparator="^1.0"
```

or manually by downloading contents and placing in desired folder.

2. Include all your files or the autoloader:

```
include "vendor/autoload.php";
```

3. Build your comparison definitions:

Assuming you have a table with schema:

idirrelevantvalue0somedate110somedate12Create new objects:

```
$comparator = new Compare();
$objects = new PdoSource();
$pdo = new PDO(...); //your database connection details here
```

In case you compare within SAME database you can use same connector (same source)

```
$objects->setPdo($pdo)
        ->setQueryAll('select * from some_table limit :limit offset :offset') //limit and offset will be dynamically updated
        ->setQuerySingle('select * from some_table where {_keys}')
        ->setSingleKeys(['id']);

$comparator->addSource('main', $objects)
           ->addSource('test', $objects); /* in this case we shall use the same
           source as for left calls it will use queryAll and for right ones
           querySingle */

$output = (new SimpleOutput())
          ->setBaseFilename('somepath/comparison_{source}.log');
          // {source} token will be dynamically replaced

$comparator->setOutput($output)
           ->run();

//report differences
var_dump($comparator->getDiffsCount());
```

4. Special cases:

In some cases you want to omit some fields - for instance if your tables have the automatic "last updated" fields. You can do it in two ways:

- do not specify it within your queries (`QueryAll`, `QuerySingle`) or in case it would be hard to do (like in SQL you would need to list all other fields) set "ignored fields":

```
$objects->setIgnoredFields(['last_updated']);
```

In case your tables / data sources have complex data sources just specify them as next array elements in `setSingleKeys`, for example:

```
$objects->setSingleKeys(['id','sub_id']);
```

One of the most interesting features of the framework is option to alter results just before comparison - this is very useful in situations when you *know* what you have changed and want to check if you achieved it. For instance: if you had an application which fills the sample table above and you made a change to your app which causes writing of the `value` field with data substracted by 2 you can still verify that using `getSinglePreCheckTransformation`method.

```
$objects->setSinglePreCheckTransformation(function($their, $mine) {
    $mine['value'] += 2;
    return $mine;
});
```

`SinglePreCheckTransformation` is meant to update the data from the current data source and should return the updated set. So in case your application substracted 2 from value of field `value` of every row/entry you can add 2 back in order to make the comparison using the code above.

contribution
============

[](#contribution)

In case you found any bugs, problems or would like to add some features... or write tests :) it is more than welcome! Please make the changes, add a pull request and I will merge it when it is possible. Thank you in advance!

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

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

3198d ago

### Community

Maintainers

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

---

Tags

validationdatabasecomparestoragecomparisondbidct

### Embed Badge

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

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

###  Alternatives

[amphp/postgres

Asynchronous PostgreSQL client for Amp.

110509.8k27](/packages/amphp-postgres)[rah/danpu

Zero-dependency MySQL dump library for easily exporting and importing databases

64401.8k10](/packages/rah-danpu)[dbout/wp-orm

WordPress ORM with Eloquent.

1279.6k1](/packages/dbout-wp-orm)[nitecon/zf2-db-session

Zend Framework 2 database session storage

204.8k](/packages/nitecon-zf2-db-session)[antonkomarev/php-db-migration-validator

Validate PHP database migration files

191.5k](/packages/antonkomarev-php-db-migration-validator)[nkiraly/dbsteward

SQL database definition differencing tool. Structure and data is defined in a DTD-enforced, human-readable XML format. Outputs transactional SQL statement files to apply your changes.

504.2k](/packages/nkiraly-dbsteward)

PHPackages © 2026

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