首页 > 解决方案 > how to log only successfully executed query in yii2 similar like profile log

问题描述

I have successfully implemented profile log in yii2 that will log all executed mysql query. But the problem is, it also log the query that are rollback during the process. I want to keep record of all successfully executed query and keep it as backup/mirror. Is there any way i can achieve this. I tried using Dbtarget log and commented the following part

 public function export() {
        if ($this->db->getTransaction()) {
   // create new database connection, if there is an open transaction
   // to ensure insert statement is not affected by a rollback
this is my comment=>// $this->db = clone $this->db; 
        }

But still it did not worked.

标签: phpyii2

解决方案


This can be achieve by checking category of query in yii2. Each query are categorized in yii2 as query,execution and each execution query starts transaction start and end with rollback or commit. So only save the execution query having that ends with commit category in Dbtarget class.


推荐阅读