/** * 重写MYSQL中的QUERY,对SQL语句进行监控 * @param string $sql */ public function query($sql, $is_set_default = true) { //echo $sql; $log = InitPHP::getUtils('log'); $log->write($sql, 'DEBUG'); $this->get_link_id($sql); //link_id获取 $InitPHP_conf = InitPHP::getConfig(); if ($InitPHP_conf['is_debug'] == true) { $start = microtime(); } $query = $this->db->query($sql); if ($InitPHP_conf['is_debug'] == true) { $end = microtime(); } //sql query debug if ($InitPHP_conf['is_debug'] == true) { $k = isset($InitPHP_conf['sqlcontrolarr']) ? count($InitPHP_conf['sqlcontrolarr']) : 0; if ($k < 50) { $InitPHP_conf['sqlcontrolarr'][$k]['sql'] = $sql; $costTime = substr($end - $start, 0, 7); $InitPHP_conf['sqlcontrolarr'][$k]['queryTime'] = $costTime; $InitPHP_conf['sqlcontrolarr'][$k]['affectedRows'] = $this->affected_rows(); InitPHP::setConfig('sqlcontrolarr', $InitPHP_conf['sqlcontrolarr']); } } if ($this->db->error()) { InitPHP::initError($this->db->error()); } if ($is_set_default) { $this->set_default_link_id(); } //设置默认的link_id return $query; }
/** * demo */ public function unittest() { InitPHP::getUtils('unittesting')->run('user'); }
/** * 通过工具库中的日志类来记录日志 * 全局使用方法:InitPHP::log("queue") * @param string $message 日志信息 * @param string $log_type 日志类型 ERROR WARN DEBUG IN */ public static function log($message, $log_type = 'DEBUG') { $log = InitPHP::getUtils("log"); //获取logInit对象实例 $log->write($message, $log_type); }