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

460.              try {
461.                  if (!class_exists("PDO") || !in_array("mysql"PDO::getAvailableDrivers(), true)) {
462.                      err('Database Err: PDO or PDO_MYSQL doesn\'t exist!');
463.                  }
464.                  $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'] . '\''));
465.              } catch (PDOException $e) {err('Database Err: ' $e->getMessage());}
466.          }
467.          return $GLOBALS['mysql_instances'][$db_config_key];
468.      }
469. 
470.      private function _where($conditions) {
427. 
428.          if ($readonly && !empty($GLOBALS['mysql']['MYSQL_SLAVE'])) {
429.              $slave_key array_rand($GLOBALS['mysql']['MYSQL_SLAVE']);
430.              $sth $this->dbInstance($GLOBALS['mysql']['MYSQL_SLAVE'][$slave_key], 'slave_' $slave_key)->prepare($sql);
431.          } else {
432.              $sth $this->dbInstance($GLOBALS['mysql'], 'master')->prepare($sql);
433.          }
434. 
435.          if (is_array($params) && !empty($params)) {
436.              foreach ($params as $k => &$v) {
437.                  if (is_int($v)) {
419.              }
420.          }
421.          return $this->page;
422.      }
423. 
424.      public function query($sql$params = array()) {return $this->execute($sql$paramstrue);}
425.      public function execute($sql$params = array(), $readonly false) {
426.          $this->sql[] = $sql;
427. 
428.          if ($readonly && !empty($GLOBALS['mysql']['MYSQL_SLAVE'])) {
429.              $slave_key array_rand($GLOBALS['mysql']['MYSQL_SLAVE']);
321.              $limit $this->pager($limit[0], $limit[1], $limit[2], $total[0]['M_COUNTER']);
322.              $limit = empty($limit) ? '' ' LIMIT ' $limit['offset'] . ',' $limit['limit'];
323.          } else {
324.              $limit = !empty($limit) ? ' LIMIT ' $limit '';
325.          }
326.          return $this->query('SELECT ' $fields $sql $sort $limit$conditions["_bindParams"]);
327.      }
328. 
329.      public function find($conditions = array(), $sort null$fields '*') {
330.          $res $this->findAll($conditions$sort$fields1);
331.          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';
144.  if (!method_exists($controller_name$action_name)) {
145.      _err_router("Err: Method '$action_name' of '$controller_name' is not exists!");
146.  }
147. 
148.  $controller_obj = new $controller_name();
149.  $controller_obj->$action_name();
150. 
151.  if ($controller_obj->_auto_display) {
152.      $auto_tpl_name = (empty($__module) ? '' $__module DS) . $__controller '_' $__action '.html';
153.      if (file_exists(APP_DIR DS 'protected' DS 'view' DS $auto_tpl_name)) {
154.          $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('站点正常哦');