Home > php教程 > php手册 > 让错误日志显示当前连接的数据库信息

让错误日志显示当前连接的数据库信息

WBOY
Release: 2016-06-07 11:36:39
Original
810 people have browsed it

在数据库分布式部署环境下,TP的错误Trace机制并不会显示是哪个数据库有问题,当我们进行排查的时候,有可能就其中某一台不正常,这时,我们就很难进行排查了,此方法将可以解决此问题。
在数据库分布式部署环境下,TP的错误Trace机制并不会显示是哪个数据库有问题,当我们进行排查的时候,有可能就其中某一台不正常,这时,我们就很难进行排查了,此方法将可以解决此问题。
找到文件:
./ThinkPHP/Library/Think/Db/Driver.class.php
第57行插入    // 数据库当前连接参数配置<br>     protected $_config = array();第97行插入            // 数据库当前连接参数配置<br>             $this->_config = $config;第110行将                if($autoConnection){<br>                     trace($e->getMessage(),'','ERR');<br>                     return $this->connect($autoConnection,$linkNum);<br>                 }elseif($config['debug']){<br>                     E($e->getMessage());<br>                 }替换成                // 输出当前数据库连接信息<br>                 $message =  $e->getMessage() . "\n [ 当前链接 ] : ".$this->_config['database'].'@'.$this->_config['hostname'].':'.$this->_config['hostport'];<br>                 if($autoConnection){<br>                     trace($message,'','ERR');<br>                     return $this->connect($autoConnection,$linkNum);<br>                 }elseif($config['debug']){<br>                     E($message);<br>                 }第345行插入        // 输出当前数据库连接信息<br>         $this->error .= "\n [ 当前链接 ] : ".$this->_config['database'].'@'.$this->_config['hostname'].':'.$this->_config['hostport'];

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template