开发者

Capturing MySQL Statement and inserting it into another db via trigger

开发者 https://www.devze.com 2023-01-21 04:06 出处:网络
I want to be able to keep a log of every sql statment that edits a specific table, and I think the best way would be with a trigger. However, I don\'t know how to get the statement that triggers the t

I want to be able to keep a log of every sql statment that edits a specific table, and I think the best way would be with a trigger. However, I don't know how to get the statement that triggers the trigger.

For example if I run:

$sql = "INSERT INTO foo (col_1) VALUES ('bar');"

I want to be able to craft an insert statement like:

$sql = "INS开发者_如何学CERT INTO log (statements) VALUES (INSERT INTO foo (col_1) VALUES ('bar')'

Is this possible with a trigger? I know I can do this easily with php, but I figured that a trigger would have less overhead.


You can't get the statements, only their results / alterations. Consider using a database abstraction- or decorator-interface to capture those queries.

0

精彩评论

暂无评论...
验证码 换一张
取 消