public function initDb($name) { $config = App::conf('app', 'database'); if (!isset($config[$name])) { throw new \InvalidArgumentException("数据配置不存在: {$name}"); } $config = $config[$name]; $db = new Db($config); if (isset($config['slow_log']) && $config['slow_log']) { // 慢查询日志 $db->addHook(Db::TAG_AFTER_QUERY, function ($data) use($config) { if ($data['time'] > $config['slow_log']) { $logger = App::logger('database'); $logger->debug("\nROUTE: " . CUR_ROUTE . "\nSQL: {$data['sql']}\nDATA: " . json_encode($data['data']) . "\nTIME: {$data['time']}\nMETHOD: {$data['method']}\n"); } }); } return $db; }