PHP code example of moledet / database-change-log
1. Go to this page and download the library: Download moledet/database-change-log library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
moledet / database-change-log example snippets
$config = array(
'database'=>'mysql',
'host'=>'localhost',
'port'=>3306,
'dbname'=>'test',
'charset'=>'utf8',
'user'=>'admin',
'password'=>'secret'
);
DatabaseChangeLog::getInstance()->setConnection($config);
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);
$sql = "UPDATE user SET password='secret' WHERE id=7;";
DatabaseChangeLog::getInstance()->log($sql);
$framework->getConnection()->runSQL($sql);
$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]);
}