PHPackages                             moledet/database-change-log - 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. moledet/database-change-log

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

moledet/database-change-log
===========================

A PHP class to log all changes of table data from raw SQL or with PDO statement

v1.0.3(1y ago)66.9k1MITPHPPHP &gt;=8.3

Since Jul 14Pushed 1y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

Universal database log of data changes by parse the sql queries for PHP
=======================================================================

[](#universal-database-log-of-data-changes-by-parse-the-sql-queries-for-php)

The DatabaseChangeLog class help to log all update, delete, insert SQL queries into table *data\_change\_log*. The class parse raw SQL or PDO query with statement only by add one string to code. In log will be save change of data and the userID, ip, userAgent and system(configurable).
The tables and columns that need log may be configurable by each action (update, delete, insert).

Installation
------------

[](#installation)

\###Download [From Git](https://github.com/moledet/database-change-log)
\###Clone

```
git clone https://github.com/moledet/database-change-log.git Log
```

\###Composer

```
php composer.phar require moledet/database-change-log
```

or add to yours *composer.json* see [the documentation](https://getcomposer.org/doc/).

```
 {
     "repositories": [
         {
             "url": "https://github.com/moledet/database-change-log",
             "type": "vcs"
         }
     ],
     "require": {
         "moledet/database-change-log": "dev-master"
     }
 }
```

\###Dependency This class depends on [PHP-SQL-Parser](https://github.com/greenlion/PHP-SQL-Parser).

Usage
-----

[](#usage)

\###Config You must config a database connection.

```
 $config = array(
    'database'=>'mysql',
    'host'=>'localhost',
    'port'=>3306,
    'dbname'=>'test',
    'charset'=>'utf8',
    'user'=>'admin',
    'password'=>'secret'
 );

 DatabaseChangeLog::getInstance()->setConnection($config);
```

May config current user id (default 0), system name(default CRM) or list of tables|columns|actions that need log. If not config the tables list - all tables changes will be logged.

```
DatabaseChangeLog::getInstance()->setUserId(7);
DatabaseChangeLog::getInstance()->setSystemName('API');

$config = [
                    'user'=>[
                        'insert'=>['login','name','password']
                        'delete'=>'all',
                        'update'=>['login','name']
                     ],
                     'customers'=>'all',
           ];

DatabaseChangeLog::getInstance()->setLogTablesConfig($config);
```

\###How to use Need put call of log sql before run. You may override framework or ORM connection to run it before query.

```
 $sql = "UPDATE user SET password='secret' WHERE id=7;";
 DatabaseChangeLog::getInstance()->log($sql);

 $framework->getConnection()->runSQL($sql);
```

Or PDO:

```
 $query = 'UPDATE users SET bonus = bonus + ? WHERE id = ?';
 $stmt = $pdo->prepare($query);
 foreach ($data as $id => $bonus)
 {
    DatabaseChangeLog::getInstance()->log($query,[$bonus,$id]);
    $stmt->execute([$bonus,$id]);
 }
```

\###Result In table *data\_change\_log* will be save the log of changes.

idactiontablecolumnnewValueoldValuedatesystemuserIdipUserAgentcolumnReferenceoperatorReferencevalueReference1updatecustomersphone77777999992017-02-02 10:33:32CRM5127.0.0.1Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36id=2894602deletecountrynullnull2017-02-03 11:33:22API1127.1.1.7Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36countryId=203insertusernameBobnull2017-02-04 15:31:52API1127.1.1.7Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36nullnullnull5insertuserphone89898null2017-02-04 15:31:52API1127.1.1.7Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36nullnullnull6insertuserpasswordsecretnull2017-02-04 15:31:52API1127.1.1.7Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36nullnullnull

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance42

Moderate activity, may be stable

Popularity26

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 58.3% 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 ~837 days

Total

3

Last Release

460d ago

PHP version history (2 changes)1.0.1PHP &gt;=5.3

v1.0.2PHP &gt;=8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/11865555?v=4)[moledet](/maintainers/moledet)[@moledet](https://github.com/moledet)

---

Top Contributors

[![serhii-m-prime](https://avatars.githubusercontent.com/u/22959931?v=4)](https://github.com/serhii-m-prime "serhii-m-prime (14 commits)")[![moledet](https://avatars.githubusercontent.com/u/11865555?v=4)](https://github.com/moledet "moledet (7 commits)")[![SerhiiMaksymenko42](https://avatars.githubusercontent.com/u/123936607?v=4)](https://github.com/SerhiiMaksymenko42 "SerhiiMaksymenko42 (3 commits)")

---

Tags

logphpdatabasesqltablecolumn

### Embed Badge

![Health badge](/badges/moledet-database-change-log/health.svg)

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

###  Alternatives

[clouddueling/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k22.9k](/packages/clouddueling-mysqldump-php)[druidfi/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

35489.8k6](/packages/druidfi-mysqldump-php)[butschster/dbml-parser

DBML (database markup language) parser written on PHP8.

6416.8k2](/packages/butschster-dbml-parser)[calebdw/laravel-sql-entities

Manage SQL entities in Laravel with ease.

301.3k](/packages/calebdw-laravel-sql-entities)

PHPackages © 2026

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