Example #1
0
 /**
  * protected封闭起来,只能通过getIns()访问
  */
 protected function __construct()
 {
     $this->conf = Config::getIns();
     $this->connect($this->conf->host, $this->conf->user, $this->conf->pwd);
     $this->select_db($this->conf->dbname);
     $this->setChar($this->conf->charset);
 }
Example #2
0
 public function connect()
 {
     //数据库配置
     $ConfigIns = Config::getIns();
     $this->config = $ConfigIns->db;
     //表前缀
     $this->tablePrefix = $this->config[0]['prefix'];
     //数据库名称
     $this->dbName = $this->config[0]['dbname'];
     foreach ($this->config as $val) {
         switch (ucwords($val['type'])) {
             //Mysql
             case 'Mysql':
                 //链接Mysql数据库服务器
                 $this->conn = mysql_connect($val['host'] . ':' . $val['port'], $val['username'], $val['password']) or die("Mysql数据库连接失败");
                 //选择数据库
                 self::select_db($val['dbname']);
                 //设置编码
                 self::setChar($val['char']);
                 break;
         }
     }
 }