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 6y 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 1w 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

18

—

LowBetter than 7% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity34

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

[jdorn/sql-formatter

a PHP SQL highlighting library

3.8k117.8M121](/packages/jdorn-sql-formatter)[backup-manager/backup-manager

A framework agnostic database backup manager with user-definable procedures and support for S3, Dropbox, FTP, SFTP, and more with drivers for popular frameworks.

1.7k1.6M11](/packages/backup-manager-backup-manager)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M88](/packages/propel-propel1)[insolita/yii2-migration-generator

Set of gii tools for generating files for migration by schema of table , phpdoc or table data

108508.0k5](/packages/insolita-yii2-migration-generator)[xpdo/xpdo

A PDO-based Object/Relational Bridge Library

7088.4k4](/packages/xpdo-xpdo)[voku/session2db

A PHP library acting as a wrapper for PHP's default session handling functions which stores data in a MySQL database, providing both better performance and better security and protection against session fixation and session hijacking.

2920.0k](/packages/voku-session2db)

PHPackages © 2026

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