douzhaishan5462 2014-06-07 13:15
浏览 74
已采纳

PHP pdo,如何将执行到数据库的每个查询作为日志存储到同一数据库中的表

working with php5.5 and mysql5.5, have developed an application with the PDO connection. now as log table I want to create a table(db_log):

id--------auto
query ----query 
create----curent time
user------session-user

AND store every insert, update and delete action on database to a mention table, for example there table named( tbl_temp) with some coumns and there user come and run query like

(DELETE * FROM tbl_temp where id = 1) from the user (user1)

here when this query runs like from the page of (delete.php).. it should save the query on the table of db_log

id = 1
query = DELETE * FROM tbl_temp where id = 1
create = datetime
user = user1

so that how i will be able to record every action of user on database and control the user activity,

1 - here do i need to pass the query to db_log in every, page, or i can build a class 2- is there any good solution or example on web to learn.

  • 写回答

1条回答 默认 最新

  • dongluan6784 2014-06-07 13:17
    关注

    You can create insert/update/delete triggers on all tables that you want to log. In that triggers you copy the data into your log table.

    For instance:

    delimiter |
    CREATE TRIGGER log_insert_tbl_temp BEFORE INSERT ON tbl_temp
    FOR EACH ROW BEGIN
       insert into db_log (table_name, action, id)
       select 'tbl_temp', 'insert', NEW.id;       
    END
    |
    delimiter ;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器