Database Err: SQLSTATE[HY000] [2002] Connection refused

462.              try {
463.                  if (!class_exists("PDO") || !in_array("mysql"PDO::getAvailableDrivers(), true)) {
464.                      err('Database Err: PDO or PDO_MYSQL doesn\'t exist!');
465.                  }
466.                  $GLOBALS['mysql_instances'][$db_config_key] = new PDO('mysql:dbname=' $db_config['MYSQL_DB'] . ';host=' $db_config['MYSQL_HOST'] . ';port=' $db_config['MYSQL_PORT'], $db_config['MYSQL_USER'], $db_config['MYSQL_PASS'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'' $db_config['MYSQL_CHARSET'] . '\''));
467.              } catch (PDOException $e) {err('Database Err: ' $e->getMessage());}
468.          }
469.          return $GLOBALS['mysql_instances'][$db_config_key];
470.      }
471. 
472.      private function _where($conditions) {
429. 
430.          if ($readonly && !empty($GLOBALS['mysql']['MYSQL_SLAVE'])) {
431.              $slave_key array_rand($GLOBALS['mysql']['MYSQL_SLAVE']);
432.              $sth $this->dbInstance($GLOBALS['mysql']['MYSQL_SLAVE'][$slave_key], 'slave_' $slave_key)->prepare($sql);
433.          } else {
434.              $sth $this->dbInstance($GLOBALS['mysql'], 'master')->prepare($sql);
435.          }
436. 
437.          if (is_array($params) && !empty($params)) {
438.              foreach ($params as $k => &$v) {
439.                  if (is_int($v)) {
421.              }
422.          }
423.          return $this->page;
424.      }
425. 
426.      public function query($sql$params = array()) {return $this->execute($sql$paramstrue);}
427.      public function execute($sql$params = array(), $readonly false) {
428.          $this->sql[] = $sql;
429. 
430.          if ($readonly && !empty($GLOBALS['mysql']['MYSQL_SLAVE'])) {
431.              $slave_key array_rand($GLOBALS['mysql']['MYSQL_SLAVE']);
323.              $limit $this->pager($limit[0], $limit[1], $limit[2], $total[0]['M_COUNTER']);
324.              $limit = empty($limit) ? '' ' LIMIT ' $limit['offset'] . ',' $limit['limit'];
325.          } else {
326.              $limit = !empty($limit) ? ' LIMIT ' $limit '';
327.          }
328.          return $this->query('SELECT ' $fields $sql $sort $limit$conditions["_bindParams"]);
329.      }
330. 
331.      public function find($conditions = array(), $sort null$fields '*') {
332.          $res $this->findAll($conditions$sort$fields1);
333.          return !empty($res) ? array_pop($res) : false;
1.  <?php
2.  class BaseController extends Controller{
3.      function conf(){
4.          $Config = new Config();
5.          $Config $Config->findAll();//获取系统配置
6.          $this->conf = array();
7.          foreach($Config as $crow){
8.              //print_r($v);
9.              $this->conf$crow['k'] ] = $crow['v'];
10.          }
1.  <?php
2.  class MainController extends BaseController {
3.      function actionIndex(){
4.          $this->conf();
5.          $template $this->conf['template']?$this->conf['template']:'default';
6.          $filename TEMPLATE_ROOT.$template.'/index.html';
7.          if(file_exists($filename)){
8.              $this->assets TEMPLATE_ROOT.$template.'/assets/';
9.              $template_index $template.'/index.html';
146.  if (!method_exists($controller_name$action_name)) {
147.      _err_router("Err: Method '$action_name' of '$controller_name' is not exists!");
148.  }
149. 
150.  $controller_obj = new $controller_name();
151.  $controller_obj->$action_name();
152. 
153.  if ($controller_obj->_auto_display) {
154.      $auto_tpl_name = (empty($__module) ? '' $__module DS) . $__controller '_' $__action '.html';
155.      if (file_exists(APP_DIR DS 'protected' DS 'view' DS $auto_tpl_name)) {
156.          $controller_obj->display($auto_tpl_name);
36.  }
37. 
38.  define('APP_DIR'realpath('./'));
39.  require(APP_DIR.'/protected/Version.php');
40.  require(APP_DIR.'/protected/lib/Common.php');
41.  require(APP_DIR.'/protected/lib/speed.php');
42. 
43.  if($_GET['runcron']){
44.      //云端防止监控自动停止
45.      $ch curl_init();curl_setopt($chCURLOPT_URL, ((int)$_SERVER['SERVER_PORT'] == 80 'http://'.$_SERVER['HTTP_HOST'] : 'https://'.$_SERVER['HTTP_HOST']).'/Crontab/Tim/Run?r='.time());curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);curl_setopt($chCURLOPT_RETURNTRANSFER1);curl_setopt($chCURLOPT_FOLLOWLOCATION1);curl_setopt($chCURLOPT_TIMEOUT1);curl_exec($ch);curl_close($ch);
46.      exit('站点正常哦');