Reputation: 333
I want to make a log details for my database while a record insert into any table and update any table and delete any record from an table in MYSQL - PHP. Please give me some ideas.
Upvotes: 1
Views: 3551
Reputation: 21
One solution is writing a helper function that logs successful insert/update sql queries if you have full control over your PHP application. A helper function can be called on every instance of insert/update queries which logs the features of the sql query you have. Some features for example can be the table name, the record id, and the type of operation i.e. insert or update, along with the system date.
In the module I have developed and have the link for below, these features are extracted from the original sql query automatically. This is one solution to the logging problem.
Here is how it works:
To see the logged data (as an interface to what we have logged):
Upvotes: 0
Reputation: 163898
You've used laravel
tag, so I assume you want to find a 'Laravel way' to do it.
The best practice is to use Eloquent Events.
Each time when Laravel will hit the DB, it will try to run some of these events: creating, created, updating, updated, saving, saved, deleting, deleted, restoring, restored
-ing
events are used before hitting DB, -ed
events are used right after hitting DB.
Example:
public function boot()
{
User::created(function () {
Log::info('User was just created successfully');
});
}
Upvotes: 1