捕获MySQL语句并通过触发器将其插入到另一个数据库中
我希望能够保留编辑特定表的每个 sql 语句的日志,我认为最好的方法是使用触发器。但是,我不知道如何获取触发触发器的语句。
例如,如果我运行:
<代码> $sql = "插入 foo (col_1) 值 ('bar');"
我希望能够制作一个插入语句,例如:
<代码> $sql = "INSERT INTO log (statements) VALUES (INSERT INTO foo (col_1) VALUES ('bar')'
这可以通过触发器实现吗?我知道我可以使用 php 轻松完成此操作,但我认为触发器的开销会更少。
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 = "INSERT 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法获得报表,只能获得它们的结果/更改。考虑使用数据库抽象或装饰器接口来捕获这些查询。
You can't get the statements, only their results / alterations. Consider using a database abstraction- or decorator-interface to capture those queries.