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

        // define('CONTROLLER', '未知'); //文件后缀
        // define('ACTION', '未知'); //文件后缀

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

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

        //记录sql
        if ($this->sqlInfo && $this->dbConfig['db_save_log']) {
            $path = DATA_PATH . 'sql_log' . DS . $this->build['database'] . DS;
            is_dir($path) ? '' : mkdir($path, 0755, true);
            if (stripos($this->sqlInfo['sql'], 'select') === 0) {

                $path .= 'select_' . date('Y_m_d_H', TIME) . '.text';
                $content = $this->sqlInfo['sql'] . PHP_EOL;

            } elseif (stripos($this->sqlInfo['sql'], 'update') === 0) {

                $path .= 'update_' . date('Y_m_d_H', TIME) . '.text';
                $content = $this->sqlInfo['sql'] . ';' . PHP_EOL;

            } elseif (stripos($this->sqlInfo['sql'], 'delete') === 0) {

                $path .= 'delete_' . date('Y_m_d_H', TIME) . '.text';
                $content = $this->sqlInfo['sql'] . ';' . PHP_EOL;

            } elseif (stripos($this->sqlInfo['sql'], 'insert') === 0) {

                $path .= 'add_' . date('Y_m_d_H', TIME) . '.text';
                $content = $this->sqlInfo['sql'] . ';' . PHP_EOL;

            } else {

                $path .= 'other_' . date('Y_m_d_H', TIME) . '.text';
                $content = $this->sqlInfo['sql'] . ';' . PHP_EOL;
            }

            //记录慢sql
            if ($this->dbConfig['db_slow_save_log']) {
                if ($this->sqlInfo['time'] > $this->dbConfig['db_slow_time']) {
                    $path .= 'slow_' . date('Y_m_d_H', TIME) . '.text';
                    $content = $this->sqlInfo['sql'] . PHP_EOL;
                }
            }

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

        // define('CONTROLLER', '未知'); //文件后缀
        // define('ACTION', '未知'); //文件后缀

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

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

        //记录sql
        if ($this->sqlInfo && $this->dbConfig['db_save_log']) {
            $path = DATA_PATH . 'sql_log' . DS . $this->build['database'] . DS;
            is_dir($path) ? '' : mkdir($path, 0755, true);
            if (stripos($this->sqlInfo['sql'], 'select') === 0) {

                $path .= 'select_' . date('Y_m_d_H', TIME) . '.text';
                $content = $this->sqlInfo['sql'] . PHP_EOL;

            } elseif (stripos($this->sqlInfo['sql'], 'update') === 0) {

                $path .= 'update_' . date('Y_m_d_H', TIME) . '.text';
                $content = $this->sqlInfo['sql'] . ';' . PHP_EOL;

            } elseif (stripos($this->sqlInfo['sql'], 'delete') === 0) {

                $path .= 'delete_' . date('Y_m_d_H', TIME) . '.text';
                $content = $this->sqlInfo['sql'] . ';' . PHP_EOL;

            } elseif (stripos($this->sqlInfo['sql'], 'insert') === 0) {

                $path .= 'add_' . date('Y_m_d_H', TIME) . '.text';
                $content = $this->sqlInfo['sql'] . ';' . PHP_EOL;

            } else {

                $path .= 'other_' . date('Y_m_d_H', TIME) . '.text';
                $content = $this->sqlInfo['sql'] . ';' . PHP_EOL;
            }

            //记录慢sql
            if ($this->dbConfig['db_slow_save_log']) {
                if ($this->sqlInfo['time'] > $this->dbConfig['db_slow_time']) {
                    $path .= 'slow_' . date('Y_m_d_H', TIME) . '.text';
                    $content = $this->sqlInfo['sql'] . PHP_EOL;
                }
            }

            $file = fopen($path, 'a');
            fwrite($file, $content . $info . PHP_EOL);
            fclose($file);
        }
    }
保存sql记录
@date   2017-10-18T13:45:16+0800
@author ChenMingjiang
@return [type]                   [description]