|
- <?php
-
- /**
- * Created by PhpStorm.
- * User: Steven
- * Date: 2016/10/12
- * Time: 10:56
- */
- require_once ROOT_PATH . '/ZZBS/Utils/util.class.php';
-
- defined('DOMAIN') or define('DOMAIN', 'zhizhuchuxing.com');
- defined('CS_DOMAIN') or define('CS_DOMAIN', 'cs.'. DOMAIN);
- defined('CS1_DOMAIN') or define('CS1_DOMAIN', 'cs1.'. DOMAIN);
-
- class DataBaseConfig
- {
- //正式数据库
- private $MYSQL_HOST = "180.168.4.58";
- private $MYSQL_USER = "root";
- private $MYSQL_PASSWORD = "123456";
- private $MYSQL_DB = "ctsdata";
- private $MYSQL_PORT = "8090";
-
- //测试数据库
- private $MYSQL_HOST1 = "180.168.4.58";
- private $MYSQL_USER1 = "root";
- private $MYSQL_PASSWORD1 = "123456";
- private $MYSQL_DB1 = "ctsdata_test";
- private $MYSQL_PORT1 = "8090";
-
- /*//原waice数据库
- private $MYSQL_HOST2 = "180.168.4.58";
- private $MYSQL_USER2 = "spider";
- private $MYSQL_PASSWORD2 = "PjGPWNUgOYe6i1Ef";
- private $MYSQL_DB2 = "waice";
- private $MYSQL_PORT2 = "8090";*/
-
- //新waice数据库【迁移到新服务器的主数据库】
- private $MYSQL_HOST2 = "106.14.56.77";
- private $MYSQL_USER2 = "spider";
- private $MYSQL_PASSWORD2 = "PjGPWNUgOYe6i1Ef";
- private $MYSQL_DB2 = "ctsdata";
- private $MYSQL_PORT2 = "3306";
-
- //Memcache配置
- private $MEMCACHE_HOST = "139.224.30.29";
- private $MEMCACHE_PORT = "11211";
- private $MEMCACHE_USER = "memcached";
- private $API_GPS_ACCOUNT = "15618818219";
- private $API_GPS_PASSWORD = "123456";
-
- /**
- * 链接正式数据库
- * @return PDO
- */
- function conn()
- {
- try {
- $pdo = new PDO("mysql:host=" . $this->MYSQL_HOST . ";port=" . $this->MYSQL_PORT . ";dbname=" . $this->MYSQL_DB, $this->MYSQL_USER, $this->MYSQL_PASSWORD, array(PDO::MYSQL_ATTR_INIT_COMMAND => "set names utf8"));
- return $pdo;
- } catch (PDOException $e) {
- zzcsUtils::writeLog('new PDO failed:' . $e->getMessage());
- }
- }
-
- /**
- * 链接测试数据库
- * @return PDO
- */
- function conn_test()
- {
- try {
- $pdo = new PDO("mysql:host=" . $this->MYSQL_HOST1 . ";port=" . $this->MYSQL_PORT1 . ";dbname=" . $this->MYSQL_DB1, $this->MYSQL_USER1, $this->MYSQL_PASSWORD1, array(PDO::MYSQL_ATTR_INIT_COMMAND => "set names utf8"));
- return $pdo;
- } catch (PDOException $e) {
- zzcsUtils::writeLog('new PDO failed:' . $e->getMessage());
- }
- }
-
- /**
- * 链接waice数据库
- * @return PDO
- */
- function conn_waice()
- {
- try {
- $pdo = new PDO("mysql:host=" . $this->MYSQL_HOST2 . ";port=" . $this->MYSQL_PORT2 . ";dbname=" . $this->MYSQL_DB2, $this->MYSQL_USER2, $this->MYSQL_PASSWORD2, array(PDO::MYSQL_ATTR_INIT_COMMAND => "set names utf8"));
- return $pdo;
- } catch (PDOException $e) {
- zzcsUtils::writeLog('new PDO failed:' . $e->getMessage());
- }
- }
-
- /**
- * 添加缓存
- * @param $key
- * @param $value
- */
- public function set_memcache($key, $value)
- {
- $mem = new Memcache;
- $mem->connect($this->MEMCACHE_HOST, $this->MEMCACHE_PORT);
- $mem->set($key, $value);
- }
-
- /**
- * 获取内存中的数据
- * @param $key
- * @return array|string
- */
- public function get_memcache($key)
- {
- $mem = new Memcache;
- $mem->connect($this->MEMCACHE_HOST, $this->MEMCACHE_PORT);
- $value = $mem->get($key);
- return $value;
- }
-
- /**
- * 删除键值对应的数据
- * @param $key
- * @return bool
- */
- public function delete_memcache($key)
- {
- $mem = new Memcache;
- $mem->connect($this->MEMCACHE_HOST, $this->MEMCACHE_PORT);
- $value = $mem->delete($key);
- return $value;
- }
-
- }
|