내 프로젝트에서 쿼리 로그를 만들어야합니다. 그래서 post_controller
후크를 만들었습니다. 실행 된 모든 쿼리를 텍스트 파일과 데이터베이스에 모두 저장합니다. 그러나 이는 SELECT
검색어에 대해서만 작동합니다. 나는 그것이 반복되는 질문 인 것을 안다. 그러나 많은 수색 후에, 나는 해결책을 찾을 수 없었다.후크를 사용하여 codeigniter에있는 쿼리 로그
설정/hooks.php : 여기
내 코드 내 config.php를 활성화$hook['post_controller'] = array(
'class' => 'LogQueryHook',
'function' => 'log_queries',
'filename' => 'log_queries.php',
'filepath' => 'hooks'
);
후크/log_queries.php
class LogQueryHook {
function log_queries() {
$CI =& get_instance();
$times = $CI->db->query_times;
//$dbs = array();
$output = NULL;
$queries = $CI->db->queries;
//print_r($queries);
if (count($queries) == 0){
$output .= "no queries\n";
}else{
foreach ($queries as $key=>$query){
$took = round(doubleval($times[$key]), 3);
$CI->db->query('INSERT INTO queryLog_tbl(`query`, `executedTime`, `timeTaken`, `executedBy`) VALUES ("'.$query.'", "'.date('Y-m-d h:i:s').'", "'.$took.'","'.$CI->session->userdata('UserID').'")');
$output .= $query . "\n";
$output .= "===[took:{$took}]\n\n";
}
}
$CI->load->helper('file');
if (! write_file(APPPATH . "/logs/queries.log.txt", $output, 'a+')){
log_message('debug','Unable to write query the file');
}
}
}
후크 : $config['enable_hooks'] = TRUE;
귀하의 제안에 감사드립니다. 내가 제안한 라이브러리를 만들었습니다. – geeth