moledet/database-change-log
Composer 安装命令:
composer require moledet/database-change-log
包简介
A PHP class to log all changes of table data from raw SQL or with PDO statement
README 文档
README
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
###Download
From Git
###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.
{
"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.
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.
| id | action | table | column | newValue | oldValue | date | system | userId | ip | UserAgent | columnReference | operatorReference | valueReference |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | update | customers | phone | 77777 | 99999 | 2017-02-02 10:33:32 | CRM | 5 | 127.0.0.1 | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36 | id | = | 289460 |
| 2 | delete | country | null | null | 2017-02-03 11:33:22 | API | 1 | 127.1.1.7 | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36 | countryId | = | 20 | |
| 3 | insert | user | name | Bob | null | 2017-02-04 15:31:52 | API | 1 | 127.1.1.7 | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36 | null | null | null |
| 5 | insert | user | phone | 89898 | null | 2017-02-04 15:31:52 | API | 1 | 127.1.1.7 | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36 | null | null | null |
| 6 | insert | user | password | secret | null | 2017-02-04 15:31:52 | API | 1 | 127.1.1.7 | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36 | null | null | null |
moledet/database-change-log 适用场景与选型建议
moledet/database-change-log 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.96k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2020 年 07 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log」 「database」 「php」 「sql」 「table」 「column」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 moledet/database-change-log 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 moledet/database-change-log 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 moledet/database-change-log 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
Laravel 5.x.x library for integration Monolog Sentry
统计信息
- 总下载量: 6.96k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-07-09