Hello again,
I tried to make some changes to not use if conditions to determine what was done and to list audit trails.
Column name for processes performed: “process”
For insert:
$ftvtk->bindValue(‘:process’, ‘Added’, PDO::PARAM_STR);
For update:
$ftvtk->bindValue(‘:process’, ‘Updated’, PDO::PARAM_STR);
For deletion
Audit trail is updating before triggering
$ftvtk->bindValue(‘:process’, ‘Deleted ‘, PDO::PARAM_STR);
Then it deletes
DELETE FROM urunler WHERE id=? LIMIT 1
I used the following sample code to trigger the delete and it works perfectly
-- loan after DELETE trigger.
DELIMITER @@
CREATE TRIGGER `loan_after_delete` AFTER DELETE ON `loan`
FOR EACH ROW BEGIN
insert into `loan_audit` (`book_code`, `student_num`, `out_date`, `due_date`, `return_date`, `audit_event`, `audit_timestamp`) values(OLD.`book_code`, OLD.`student_num`, OLD.`out_date`, OLD.`due_date`, OLD.`return_date`, 'delete', CURRENT_TIMESTAMP);
END;
I am not sorting correctly the “ORDER BY done_at DESC” command to list by date.
How can I sort by date?
Date format: 2022-02-03 13:40:39
Thank you