Page 1 of 1

DB Logging actions

Posted: Sat Oct 21, 2023 6:05 pm
by shuray
Hi everyone!

I would like to log any changes of my db tables to special table like:
  • time, user, table_name, [old field value - new field value, old field value - new field value, ...]

I can realize this feature using MySQL storing procedure and TRIGGERs, but on the SQL side I don't know the actual nuBuilder user.
Probably you can advise some ideas how to approach to this task?

Thx

Re: DB Logging actions

Posted: Sun Oct 22, 2023 3:00 pm
by nac
This thread has the code that you are looking for, shuray

https://forums.nubuilder.cloud/viewtopic.php?p=16394

Neil

Re: DB Logging actions

Posted: Sun Oct 22, 2023 9:23 pm
by nac
shuray,

One more thing..
I subsequently modified the code shown in the thread to use a prepared statement instead.

Code: Select all

$S = "REPLACE INTO changelog (changelog_id, tablename, fieldname, pkvalue, userid, oldvalue, newvalue) VALUES ( ?, ?, ?, ?, ?, ?, ? )";
nuRunQuery($S, [$ID, $Tbl, $Fld, $PK, $Usr, $OV, $NV]);
This makes it injection-safe.

Neil

Re: DB Logging actions

Posted: Mon Oct 23, 2023 2:48 pm
by shuray
Wow! Thank you!