Database Err: SQLSTATE[HY000] [1040] Too many connections

356.      }
357.      public function dbInstance($db_config$db_config_key$force_replace false){
358.          if($force_replace || empty($GLOBALS['mysql_instances'][$db_config_key])){
359.              try {
360.                  $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'].'\''));
361.              }catch(PDOException $e){err('Database Err: '.$e->getMessage());}
362.          }
363.          return $GLOBALS['mysql_instances'][$db_config_key];
364.      }
365.      private function _where($conditions){
366.          $result = array( "_where" => " ","_bindParams" => array());
343.          $this->sql[] = $sql;
344.          if($readonly && !empty($GLOBALS['mysql']['MYSQL_SLAVE'])){
345.              $slave_key array_rand($GLOBALS['mysql']['MYSQL_SLAVE']);
346.              $sth $this->dbInstance($GLOBALS['mysql']['MYSQL_SLAVE'][$slave_key], 'slave_'.$slave_key)->prepare($sql);
347.          }else{
348.              $sth $this->dbInstance($GLOBALS['mysql'], 'master')->prepare($sql);
349.          }
350.          if(is_array($params) && !empty($params)){
351.              foreach($params as $k=>&$v$sth->bindParam($k$v);
352.          }
353.          if($sth->execute())return $readonly $sth->fetchAll(PDO::FETCH_ASSOC) : $sth->rowCount();
336.                  $this->page['all_pages'] = range($total_page-$scope+1$total_page);
337.              }
338.          }
339.          return $this->page;
340.      }
341.      public function query($sql$params = array()){return $this->execute($sql$paramstrue);}
342.      public function execute($sql$params = array(), $readonly false){
343.          $this->sql[] = $sql;
344.          if($readonly && !empty($GLOBALS['mysql']['MYSQL_SLAVE'])){
345.              $slave_key array_rand($GLOBALS['mysql']['MYSQL_SLAVE']);
346.              $sth $this->dbInstance($GLOBALS['mysql']['MYSQL_SLAVE'][$slave_key], 'slave_'.$slave_key)->prepare($sql);
255.              $limit $this->pager($limit[0], $limit[1], $limit[2], $total[0]['M_COUNTER']);
256.              $limit = empty($limit) ? '' ' LIMIT '.$limit['offset'].','.$limit['limit'];            
257.          }else{
258.              $limit = !empty($limit) ? ' LIMIT '.$limit '';
259.          }
260.          return $this->query('SELECT '$fields $sql $sort $limit$conditions["_bindParams"]);
261.      }
262.      public function find($conditions = array(), $sort null$fields '*'){
263.          $res $this->findAll($conditions$sort$fields1);
264.          return !empty($res) ? array_pop($res) : false;
265.      }
258.              $limit = !empty($limit) ? ' LIMIT '.$limit '';
259.          }
260.          return $this->query('SELECT '$fields $sql $sort $limit$conditions["_bindParams"]);
261.      }
262.      public function find($conditions = array(), $sort null$fields '*'){
263.          $res $this->findAll($conditions$sort$fields1);
264.          return !empty($res) ? array_pop($res) : false;
265.      }
266.      public function findfield($conditions = array(), $sort null$fields '*'){
267.          $res $this->find($conditions$sort$fields); 
268.          return !empty($res) ?  $res[$fields] : false;
79.              $row=$obj->find($param,$sort,$title);
80.              S($sqlstr,$row,CACHE_TIME,$path);
81.              return $row;
82.          }
83.      }else{ 
84.          $row=$obj->find($param,$sort,$title); 
85.          return $row;
86.      }
87.   }
88.  /**
89.   根据条件返回sql记录 
3. 
4.    function _init(){
5.      /*if(isMobile()){
6.        header('location:'.url('news/wap','index'));exit;
7.      }*/
8.      $sys=get_model_one(null'news_sys','*');
9.      $webconfig=json_decode($sys['webconfig'],true);
10.      $this->path='/addons/news/view/comp/'.$webconfig['modelcomp'];
11.      $this->subpath='comp/'.$webconfig['modelcomp'];
12.      $this->catelist=get_model_other(array('is_view'), 'news_cate','id,title,pid');
13.      $this->sys=$sys;  
211.           
212.      }
213.      public function __construct(){
214.           $this->init();
215.          /* 简介构造方法 */
216.          if(method_exists($this,'_init')){$this->_init();}
217.      }
218.      public function __get($name){return $this->_data[$name];}
219.      public function __set($name$value){$this->_data[$name] = $value;}
220.      public function display($tpl_name=''$return false){
221.      if($tpl_name==''){$tpl_name=$this->ca.'.html';};
111.              $str="Err: Method '$action_name   ' of '$controller_name' is not exists!";
112.          }
113.          BaseController::err404($str);
114.      }
115.  }
116.  $controller_obj = new $controller_name();
117.  $controller_obj->$action_name();
118.   
119. 
120.  if($controller_obj->_auto_display){
121.      $auto_tpl_dir = (empty($__module) ?   'wlb'DS.'view' ADDONS.DS.$__module.DS.'view');
7.  define('APP_DIR'realpath('./')); 
8.  define ('SITE_DOMAIN'strip_tags $_SERVER ['HTTP_HOST'] ) );
9.  define ('SITE_PATH'dirname __FILE__ ) );  
10.  define('SYSNAME'"逆境磨砺德行");
11.  define('IN',true);    
12.  require(APP_DIR.'/wlb/lib/speed.php');