src/db/BuildSql.php
public function addSqlLog()
    {
        // 如果没有写入权限尝试修改权限 如果修改后还是失败 则跳过
        if (!isWritable(DATA_PATH)) {
            return false;
        }

        //创建文件夹
        is_dir(DATA_SQL_PATH) ? '' : mkdir(DATA_SQL_PATH, 0755, true);

        $info = '------ ' . $this->sqlInfo['time'];
        $info .= ' | ' . date('Y-m-d H:i:s', TIME);
        $info .= ' | ip:' . getIP();
        $info .= ' | Url:' . URL . '/' . Route::$uri;
        $info .= PHP_EOL . PHP_EOL;

        // 如果存在sql信息 并且开启日志记录
        if ($this->sqlInfo && $this->config['save_log']) {
            $basePath = DATA_SQL_PATH . $this->options['database'] . DS;
            is_dir($basePath) ? '' : mkdir($basePath, 0755, true);

            $content = $this->sqlInfo['sql'] . PHP_EOL;

            // 记录explain
            if ($this->config['sql_explain'] && isset($this->sqlInfo['explain'])) {
                foreach ($this->sqlInfo['explain'] as $explain) {
                    $content .= json_encode($explain) . PHP_EOL;
                }
            }

            $path = $basePath . (isset($this->options['type']) ? strtolower($this->options['type']) : 'other');
            $path .= '_' . date('Y_m_d_H', TIME) . '.text';

            // 记录慢sql
            if ($this->config['slow_log']) {
                if ($this->sqlInfo['time'] > $this->config['slow_time']) {
                    $path = $basePath . 'slow_' . date('Y_m_d_H', TIME) . '.text';
                }
            }

            error_log($content . $info, 3, $path);
        }
    }
public function addSqlLog()
    {
        // 如果没有写入权限尝试修改权限 如果修改后还是失败 则跳过
        if (!isWritable(DATA_PATH)) {
            return false;
        }

        //创建文件夹
        is_dir(DATA_SQL_PATH) ? '' : mkdir(DATA_SQL_PATH, 0755, true);

        $info = '------ ' . $this->sqlInfo['time'];
        $info .= ' | ' . date('Y-m-d H:i:s', TIME);
        $info .= ' | ip:' . getIP();
        $info .= ' | Url:' . URL . '/' . Route::$uri;
        $info .= PHP_EOL . PHP_EOL;

        // 如果存在sql信息 并且开启日志记录
        if ($this->sqlInfo && $this->config['save_log']) {
            $basePath = DATA_SQL_PATH . $this->options['database'] . DS;
            is_dir($basePath) ? '' : mkdir($basePath, 0755, true);

            $content = $this->sqlInfo['sql'] . PHP_EOL;

            // 记录explain
            if ($this->config['sql_explain'] && isset($this->sqlInfo['explain'])) {
                foreach ($this->sqlInfo['explain'] as $explain) {
                    $content .= json_encode($explain) . PHP_EOL;
                }
            }

            $path = $basePath . (isset($this->options['type']) ? strtolower($this->options['type']) : 'other');
            $path .= '_' . date('Y_m_d_H', TIME) . '.text';

            // 记录慢sql
            if ($this->config['slow_log']) {
                if ($this->sqlInfo['time'] > $this->config['slow_time']) {
                    $path = $basePath . 'slow_' . date('Y_m_d_H', TIME) . '.text';
                }
            }

            error_log($content . $info, 3, $path);
        }
    }
保存sql记录
@date   2017-10-18T13:45:16+0800
@author ChenMingjiang
@return [type]                   [description]