Welcome Guest, Not a member yet? Register   Sign In
is it nomol sql log is duplicate statement ?
#1

(This post was last modified: 01-12-2018, 12:30 AM by tereaksmey123.)

i had problem with my site and sometime i'm headache with read many log Big Grin 

i notice some statement is repeated 2 time in log file

my queryLog
Code:
function log_queries() {
   $CI =& get_instance();
   $filepath = APPPATH . 'logs/Query-log-' . date('Y-m-d') . '.txt';
   $output ='';
   $times = $CI->db->query_times;
   $queries = $CI->db->queries;
   if (count($queries) == 0)
   {
       $output .= "no queries\n";
   }    
   else
   {
       foreach ($queries as $key => $query)
       {
           $whoIsThat = $CI->session->userdata('userName') . '(' . $this->input->ip_address() . ')';
           $output .= "- BY: {$whoIsThat}\n- Date:" . date('d-M-y H:i:s')."\n".$query . "\n";
       }
       $output.= "=== \n";
   }

   $CI->load->helper ('file');
    
   if ( ! write_file ($filepath, $output, 'a+')) {
       log_message ('debug', 'Unable to write query the file');
   }
}

that my delete function
Code:
public function general_delete($id, $table)
{
    $this->db->where($id);
   if(!$this->db->delete($table))
   {
       return FALSE;
   }
   $this->log_queries();
   return TRUE;
}

so this is how i call it in controller
PHP Code:
if ($this->General_model->general_delete(['fm_id' => $id], $this->tbl_firmware))
{
 
   $affect_result     $this->db->affected_rows();
 
   $error             = ['error' => "({$affect_result})Rows has been delete successfully."];
 
   $this->session->set_flashdata('show''0');

 
   $countReportUpdate $this->General_model->get_count_where(['fm_id' => $id], $this->tbl_firmware_report);
 
   if ($countReportUpdate 0)
 
   {
 
       if ( ! $this->General_model->general_delete(['fm_id' => $id], $this->tbl_firmware_report)){
 
           $error = ['error' => "({$affect_result})Rows has been delete.<br>Fail to delete report data : ID {$id}."];
 
       }
 
   }
 } 
so the log i got is duplicate of Delete statement from tbl_firmware

Code:
- BY: admin(::1)
- Date:12-Jan-18 14:12:14
DELETE FROM `tbl_firmware`
WHERE `fm_id` = '77'
===
- BY: admin(::1)
- Date:12-Jan-18 14:12:14
DELETE FROM `tbl_firmware`
WHERE `fm_id` = '77'
- BY: admin(::1)
- Date:12-Jan-18 14:12:14
SELECT COUNT(*) AS `numrows`
FROM `tbl_firmware_report`
WHERE `fm_id` = '77'
- BY: admin(::1)
- Date:12-Jan-18 14:12:14
DELETE FROM `tbl_firmware_report`
WHERE `fm_id` = '77'
===
u can see Log above it is 2 time write file `DELETE FROM `tbl_firmware WHERE `fm_id` = '77'`

is it nomol or problem my code that make it duplicate statement in log file ? Huh

Thank in advance. Heart
Reply




Theme © iAndrew 2016 - Forum software by © MyBB