protected function __construct(){ $this->conf = conf::getIns(); $this->connect($this->conf->host, $this->conf->user, $this->conf->pwd); $this->select_db($this->conf->db); $this->setChar($this->conf->char); }
protected function __construct() { // require(ROOT.'include/configclass.php'); $this->conf = conf::getIns(); $this->connect($this->conf->host, $this->conf->user, $this->conf->pwd); $this->select_db($this->conf->db); $this->setChar($this->conf->char); }
protected function __construct() { //把conf.class.php $conf数组传过来给这个类的$conf 以实现单例模式 //过程是最行先把config.inc.php 的$CFG数组传给conf.class.php 实现单例,然后再从conf.class.php 把数组传到mysql.class.php 类里$conf;过程 //就是这样的. //实现单例模式传数组数据 $this->conf = conf::getIns(); //连接数据库 $this->connect($this->conf->host, $this->conf->user, $this->conf->pwd); //选库 $this->select_db($this->conf->db); //选择字符集 $this->setChar($this->conf->char); }
public static function getIns() { if (self::$ins === null) { self::$ins = new self(); } $conf = conf::getIns(); self::$ins->host = $conf->host; self::$ins->user = $conf->user; self::$ins->passwd = $conf->pwd; self::$ins->db = $conf->db; self::$ins->port = $conf->port; self::$ins->connect(); self::$ins->select_db(); self::$ins->setChar(); return self::$ins; }
<? /*** 所有由用户直接访问的这些页面 都得先加载 init.php ***/ header('Content-Type:text/html;charset=utf-8'); require('./include/init.php'); $conf = conf::getIns(); /* echo '<pre>'; print_r($conf); echo '</pre>'; echo '---------------------获取属性-------------------<br />'; echo '主机是:',$conf->host,'<br />'; echo '用户名是:',$conf->user,'<br />'; echo '----------------------设置属性------------------<br />'; $conf->email = '*****@*****.**'; echo '<pre>'; print_r($conf); echo '</pre>'; echo '<br />'; var_dump($conf->template_dir);