A set of PHP scripts which leverage MySQL INFORMATION_SCHEMA to create log tables and insert / update triggers

Overview

mysql-logtable-php

mysql-logtable-php is a set of PHP scripts which leverage MySQL INFORMATION_SCHEMA to create log tables and insert / update triggers.

Configuration

Get started by entering your database credentials in configure.php.

6   $hostname = '{hostname}';
7   $username = '{username}';
8   $password = '{password}';
9   $database = '{database}';

Execute

Execute the scripts from your favorite browser by visiting:

1   /mysql-logtable-php/create_table_logs.php
2   /mysql-logtable-php/create_triggers.php

The browser will display minified code. Go to view source for formatted code.

Demo

Schema for demo_mysql_logtable_php

CREATE DATABASE demo_mysql_logtable_php CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE demo_mysql_logtable_php;

DROP TABLE IF EXISTS client;
CREATE TABLE client (
    client_id INT NOT NULL AUTO_INCREMENT,
    client_email VARCHAR ( 50 ) NOT NULL,
    client_passcode_hash BINARY ( 128 ),
    client_salt CHAR ( 36 ),
    last_modified_datetime TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY ( client_id ),
    CONSTRAINT unique_client_email UNIQUE ( client_email )
);

Output

1   http://localhost/mysql-logtable-php/create_table_logs.php

-- ----------------------------
-- Table structure for __client
-- ----------------------------
DROP TABLE IF EXISTS __client;
CREATE TABLE __client (
    id INT NOT NULL AUTO_INCREMENT,
    action CHAR ( 6 ),
    client_id INT,
    client_email VARCHAR ( 50 ),
    client_passcode_hash BINARY ( 128 ),
    client_salt CHAR ( 36 ),
    last_modified_datetime TIMESTAMP,
    PRIMARY KEY ( id )
);


2   http://localhost/mysql-logtable-php/create_triggers.php

DELIMITER ;;

-- ----------------------------
-- Trigger for trigger_client_insert
-- ----------------------------
DROP TRIGGER IF EXISTS trigger_client_insert;;
CREATE TRIGGER trigger_client_insert AFTER INSERT ON client
FOR EACH ROW
BEGIN

    INSERT INTO __client
    SET action = 'insert',
        client_id = NEW.client_id,
        client_email = NEW.client_email,
        client_passcode_hash = NEW.client_passcode_hash,
        client_salt = NEW.client_salt,
        last_modified_datetime = NEW.last_modified_datetime;
        
END;;

-- ----------------------------
-- Trigger for trigger_client_update
-- ----------------------------
DROP TRIGGER IF EXISTS trigger_client_update;;
CREATE TRIGGER trigger_client_update AFTER UPDATE ON client
FOR EACH ROW
BEGIN

    INSERT INTO __client
    SET action = 'update',
        client_id = NEW.client_id,
        client_email = NEW.client_email,
        client_passcode_hash = NEW.client_passcode_hash,
        client_salt = NEW.client_salt,
        last_modified_datetime = NEW.last_modified_datetime;
        
END;;

DELIMITER ;

Contact

If you are having issues, please create an issue on GitHub.

Project Link: https://github.com/stavo-dev/mysql-logtable-php

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

You might also like...
Tables migrations seeded with data according to the Algerian education system structure.
Tables migrations seeded with data according to the Algerian education system structure.

Laravel algerian education system structure If you are building a Learning Management System or a School Management System and targeting the Algerian

The swiss army knife for Magento developers, sysadmins and devops. The tool provides a huge set of well tested command line commands which save hours of work time. All commands are extendable by a module API.

netz98 magerun CLI tools for Magento 2 The n98 magerun cli tools provides some handy tools to work with Magento from command line. Build Status Latest

CrateKeyShopGUI Pocketmine-MP plugin which can be set in Config.yml file

CrateKeyShopGUI CrateKeyShopGUI Pocketmine-MP plugin which can be set in Config.yml file Depend FormAPI EconomyAPI PiggyCrate InvCrashFix Download Dow

A set of classes to create and manipulate HTML objects abstractions

HTMLObject HTMLObject is a set of classes to create and manipulate HTML objects abstractions. Static calls to the classes echo Element::p('text')-cla

A lot of scripts and packages in modern PHP demand one or more configuration classes

A lot of scripts and packages in modern PHP demand one or more configuration classes. Mostly, those are a set of properties that can be set, changed or retrieved. However, some of the configurations have a peculiar behaviour - such as boolean properties.

Online Food Delivery Website created using HTML, CSS, PHP and MySQL which delivers food at your doorstep on Cash-On-Delivery.

Food-Delivery-Website Online Food Delivery Website created using HTML, CSS, PHP and MySQL which delivers food at your doorstep on Cash-On-Delivery. Th

Magento-bulk - Bulk Import/Export helper scripts and CLI utilities for Magento Commerce

Magento Bulk Bulk operations for Magento. Configuration Copy config.php.sample to config.php and edit it. Product Attribute Management List All Attrib

Run PHP scripts on the fly at runtime on a PocketMine-MP server (useful for debugging)

Scripter Run PHP scripts on the fly at runtime on a PocketMine-MP server. This is useful for runtime debugging, when you don't want to restart the ser

Block malicious scripts using botscout.com protection for your laravel app
Block malicious scripts using botscout.com protection for your laravel app

Laravel BotScout Protect your website against automated scripts using the botscout.com API. Installation You can install the package via composer: com

Owner
null
A collection of command line scripts for Magento 2 code generation, and a PHP module system for organizing command line scripts.

What is Pestle? Pestle is A PHP Framework for creating and organizing command line programs An experiment in implementing python style module imports

Alan Storm 526 Dec 5, 2022
The simplest way to create a dynamic sitemap for your self-coded website which you have made by using PHP/HTML/CSS/Js etc... Scripts.

Sitemap_index.xml The simplest way to create a dynamic sitemap for your self-coded website which you have made by using PHP/HTML/CSS/Js etc... Scripts

Tanish Raj 1 Oct 16, 2021
CRUD Build a system to insert student name information, grade the class name, and edit and delete this information

CRUD Build a system to insert student name information, grade the class name, and edit and delete this information

Sajjad 2 Aug 14, 2022
Symfony Bundle to create HTML tables with bootstrap-table for Doctrine Entities.

HelloBootstrapTableBundle This Bundle provides simple bootstrap-table configuration for your Doctrine Entities. Used bootstrap-table version 1.18.3. I

Sebastian B 7 Nov 3, 2022
Sends log messages to the Logentries log management service

Phalcon Logentries Phalcon library to connect and make log entries using Logentries. You can adapt it to your own needs or improve it if you want. Ple

Phalcon Orphanage 10 Apr 15, 2019
Create and update progress bars in different environments

Create and update progress bars in different environments

Laminas Project 8 Jul 28, 2022
Naive Bayes works by looking at a training set and making a guess based on that set.

Naive Bayes Naive Bayes works by looking at a training set and making a guess based on that set. It uses simple statistics and a bit of math to calcul

Assisted Mindfulness 29 Nov 27, 2022
Magento extension which makes it impossible for a customer to log in until the account has been activated by the administrator.

This Magento 1 extension is orphaned, unsupported and no longer maintained. If you use it, you are effectively adopting the code for your own project.

Vinai Kopp 120 Oct 10, 2022
BetterWPDB - Keeps you safe and sane when working with custom tables in WordPress.

BetterWPDB - Keeps you safe and sane when working with custom tables in WordPress.

Snicco 21 Dec 15, 2022
A smart way of seeding tables in Laravel

SmartSeeder for Laravel For Laravel 5, please use the 5.0 branch! For Laravel 4, please use the 4.2 branch! Seeding as it is currently done in Laravel

Jordan Lapp 190 Oct 6, 2022