duanhe2027 2018-10-05 11:29
浏览 89
已采纳

获取codeigniter中所有数据库查询的列表(在ajax请求中)

I'm using codeigniter

now my ajax request its very slow and I want to find the reason

in ajax request, I want to save all DB query in a log file

it's possible?

  • 写回答

2条回答 默认 最新

  • douzong5057 2018-10-05 11:40
    关注

    you can turn on db loging in config file:

    $db['default'] = array(
       ...
       'save_queries' => TRUE
       ....
    );
    

    then end of ajax request use $queries = $this->db->queries; to get all SQL query

    $log .= join("
    ",$this->db->queries);
    $myfile = file_put_contents('logs.txt', $txt.PHP_EOL , FILE_APPEND | LOCK_EX);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • dongposhi8677 2018-10-05 11:34
    关注

    Just enable slow query log on database. E.g. on MySQL:

    SET GLOBAL slow_query_log = 'ON';
    SET GLOBAL long_query_time = X;
    SET GLOBAL slow_query_log_file = '/path/filename';
    

    X - it logs any query that takes longer than X seconds to run. Default value is 10 seconds.

    /path/filename - A path for log file. Default value is /var/lib/mysql/{hostname}-slow.log

    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Tpad api账户 api口令
  • ¥30 ppt进度条制作,vba语言
  • ¥15 stc12c5a60s2单片机测光敏ADC
  • ¥15 生信simpleaffy包下载
  • ¥15 请教一下simulink中S函数相关问题
  • ¥15 在二层网络中,掩码存在包含关系即可通信
  • ¥15 端口转发器解析失败不知道电脑设置了啥
  • ¥15 Latex算法流程图行号自定义
  • ¥15 关于#python#的问题:我在自己的电脑上运行起来总是报错,希望能给我一个详细的教程,(开发工具-github)
  • ¥40 基于51单片机实现球赛计分器功能