PHPackages                             coderofsalvation/sql-table-diff - 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. coderofsalvation/sql-table-diff

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

coderofsalvation/sql-table-diff
===============================

Find differences between 2 similar SQL tables. Compare large collections of data fast and stylish

013PHP

Since May 28Pushed 5y ago1 watchersCompare

[ Source](https://github.com/coderofsalvation/sql-diff-table)[ Packagist](https://packagist.org/packages/coderofsalvation/sql-table-diff)[ RSS](/packages/coderofsalvation-sql-table-diff/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

SQL Table Diff
==============

[](#sql-table-diff)

 [![](https://camo.githubusercontent.com/70f898e01518988d512762e90f946bef338d46cb1027e75f38bf5f4f4bfde49f/687474703a2f2f7777772e67696662696e2e636f6d2f62696e2f3034323031342f313339363435373338325f7065656c696e675f6170706c65735f776974685f706f7765725f6472696c6c2e676966)](https://camo.githubusercontent.com/70f898e01518988d512762e90f946bef338d46cb1027e75f38bf5f4f4bfde49f/687474703a2f2f7777772e67696662696e2e636f6d2f62696e2f3034323031342f313339363435373338325f7065656c696e675f6170706c65735f776974685f706f7765725f6472696c6c2e676966)

Find differences between 2 similar SQL tables. Compare large collections of data fast and stylish. Usage
-----

[](#usage)

```
$ composer require coderofsalvation/sql-diff-table

```

And then

```
// 2 db handlers since some frameworks use a separate read- and write-handler
$a = new SQLTableDiff( "sync_products_A", $dbConn, $dbConn );
$b = new SQLTableDiff( "sync_products_B", $dbConn, $dbConn );

// create 2 SQL tables based on the object fields
$a->createTableFromFields( array_keys($productsA[0]) );
$b->createTableFromFields( array_keys($productsB[0]) );
// fill the 2 SQL tables
foreach( $productsA as $p ) $sm->addRow( $p );
foreach( $productsB as $p ) $si->addRow( $p );

/*
 * get products which have similar id-value but different stock-value
 */

$filter = (object)array(
  'tableA' => "sync_products_A",
  'tableB' => "sync_products_B",
  'id'     => "sku",              // match on id field
  'fields' => array("stock")      // compare these fields
);

// SQL query is generated and the differences are returned as a result
$result = $sm->diff( $filter);
// there you go!

```

Todo
----

[](#todo)

- use closure for SQL query execution

Notes
-----

[](#notes)

Multiple-insertions-per-query takes place using smart-buffering, which makes importing large datasets ultrafast.

Hint
----

[](#hint)

If you want to compare large collections with items, sometimes the items are not compatible. For example, if you want to compare products from an csv export with products in your database. In that case you might want to transform the collections to a middleware-format. [DataMapper](https://github.com/coderofsalvation/datamapper-minimal) allows you to do that. After you mapped it to your middleware-format, then you can proceed inserting it into the db using `createTableFormFields()`

License
-------

[](#license)

BSD

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 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/f3ff28af20ec6cdc02a9b020c1f9ef72012f8a597c3b2e5ffd17ac032e893945?d=identicon)[coderofsalvation](/maintainers/coderofsalvation)

---

Top Contributors

[![coderofsalvation](https://avatars.githubusercontent.com/u/180068?v=4)](https://github.com/coderofsalvation "coderofsalvation (8 commits)")

### Embed Badge

![Health badge](/badges/coderofsalvation-sql-table-diff/health.svg)

```
[![Health](https://phpackages.com/badges/coderofsalvation-sql-table-diff/health.svg)](https://phpackages.com/packages/coderofsalvation-sql-table-diff)
```

###  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)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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