<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class ZSB_growth {

    public function __construct()
    {
        $CI =& get_instance();
        //$CI->load->helper('url');
        //$CI->load->library('session');
        //$CI->config->item('base_url');
        $config = $CI->config->item('growth');
        
        //加载db
        $CI->load->library('My_DB','','mydb');
        $this->db = $CI->mydb->get_db_obj('db');

        //加载dbback
        $CI->load->library('My_DB','','mydbback');
        $this->dbback = $CI->mydbback->get_db_obj('dbback');

        $conf_db_type = $this->db->dbdriver;
        $conf_db_host = $this->db->hostname;//"172.17.1.50";//master_nj_esf
        $conf_db_user = $this->db->username;//"root";
        $conf_db_password = $this->db->password;//"idontcare";
        $conf_db_name = $this->db->database;//"house";
        $conf_db_debug = false;//$this->db->db_debug;//false;
        $conf_db_charset = $this->db->char_set;//"gbk";
        $conf_db_connect = $this->db->pconnect;//"0";

		$dbConfigArr = array(
			'conf_db_type' => $conf_db_type,
			'conf_db_host' => $conf_db_host,
			'conf_db_user' => $conf_db_user,
			'conf_db_password' => $conf_db_password,
			'conf_db_name' => $conf_db_name,
			'conf_db_debug' => $conf_db_debug,
			'conf_db_charset' => $conf_db_charset,
			'conf_db_connect' => $conf_db_connect,
			'dbObject' => $this->db->conn_id
		);

        //print_r($this->memcached);exit;
        //$dbobj = new SIMPLE_DB($conf_db_type,$conf_db_host,$conf_db_user,$conf_db_password,$conf_db_name,$conf_db_charset,$conf_db_debug,$this->db->conn_id);
        
        $conf_db_type = $this->dbback->dbdriver;
        $conf_db_host = $this->dbback->hostname;//"172.17.1.50";//master_nj_esf
        $conf_db_user = $this->dbback->username;//"root";
        $conf_db_password = $this->dbback->password;//"idontcare";
        $conf_db_name = $this->dbback->database;//"house";
        $conf_db_debug = false;//$this->db->db_debug;//false;
        $conf_db_charset = $this->dbback->char_set;//"gbk";
        $conf_db_connect = $this->dbback->pconnect;//"0";

		$dbbackConfigArr = array(
			'conf_db_type' => $conf_db_type,
			'conf_db_host' => $conf_db_host,
			'conf_db_user' => $conf_db_user,
			'conf_db_password' => $conf_db_password,
			'conf_db_name' => $conf_db_name,
			'conf_db_debug' => $conf_db_debug,
			'conf_db_charset' => $conf_db_charset,
			'conf_db_connect' => $conf_db_connect,
			'dbObject' => $this->db->conn_id
		);

        //$dbbackobj = new SIMPLE_DB($conf_db_type,$conf_db_host,$conf_db_user,$conf_db_password,$conf_db_name,$conf_db_charset,$conf_db_debug,$this->db->conn_id);

        //$this->memcached = $CI->load->library('My_memcached',null,'memcached');
        $MCache = new MCache(GB_CITY,$config['memcache']);//第二个参数表示是否开启缓存
        $mc = new Memcache;
		//$mc->connect('172.17.1.57', 1122) or die ("Could not connect");
		$IpHostAllow =explode('.',GetIp());
        //if($IpHostAllow['0']=='192' || $IpHostAllow['0']=='127')
        $server_ip = $_SERVER['SERVER_ADDR'];
        if($server_ip == '192.168.105.106')//租售宝内网地址
		{
			if(GB_CITY=='nj')
			{
				$mc_str ='127.0.0.1';
			}
			else
			{
				$mc_str ='127.0.0.1';
			}
			$mc_str_port ="1122";
		}
		else
		{
			$mc_str = $this->rand_server();
			$mc_str_port ="11211";
		}

        //$mc->connect($mc_str, $mc_str_port) or die ("Could not connect memcache");
        $mc->connect($mc_str, $mc_str_port);
        $MCache->initMc($mc);
        //print_r($MCache);exit;
        //include_once Growth::getCoreLibDir().'/growth/Container.php';

        $container = Container::getInstance();
		$container->set('dbConfigArr', $dbConfigArr);
        $container->set('dbbackConfigArr', $dbbackConfigArr);

        //$container->set('db', $dbobj);
        //$container->set('dbback', $dbbackobj);

        $container->set('mc', $MCache);
        $this->container = $container;
		
    }

    public function rand_server(){
       /* $ips = array('172.17.1.96','172.17.1.97');
        $key = array_rand($ips);
        return $ips[$key];*/

        return '172.17.1.97';
    }

}

/* End of file Someclass.php */
