No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

132 líneas
3.7 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Steven
  5. * Date: 2016/10/12
  6. * Time: 10:56
  7. */
  8. require_once ROOT_PATH . '/ZZBS/Utils/util.class.php';
  9. defined('DOMAIN') or define('DOMAIN', 'zhizhuchuxing.com');
  10. defined('CS_DOMAIN') or define('CS_DOMAIN', 'cs.'. DOMAIN);
  11. defined('CS1_DOMAIN') or define('CS1_DOMAIN', 'cs1.'. DOMAIN);
  12. class DataBaseConfig
  13. {
  14. //正式数据库
  15. private $MYSQL_HOST = "180.168.4.58";
  16. private $MYSQL_USER = "root";
  17. private $MYSQL_PASSWORD = "123456";
  18. private $MYSQL_DB = "ctsdata";
  19. private $MYSQL_PORT = "8090";
  20. //测试数据库
  21. private $MYSQL_HOST1 = "180.168.4.58";
  22. private $MYSQL_USER1 = "root";
  23. private $MYSQL_PASSWORD1 = "123456";
  24. private $MYSQL_DB1 = "ctsdata_test";
  25. private $MYSQL_PORT1 = "8090";
  26. /*//原waice数据库
  27. private $MYSQL_HOST2 = "180.168.4.58";
  28. private $MYSQL_USER2 = "spider";
  29. private $MYSQL_PASSWORD2 = "PjGPWNUgOYe6i1Ef";
  30. private $MYSQL_DB2 = "waice";
  31. private $MYSQL_PORT2 = "8090";*/
  32. //新waice数据库【迁移到新服务器的主数据库】
  33. private $MYSQL_HOST2 = "106.14.56.77";
  34. private $MYSQL_USER2 = "spider";
  35. private $MYSQL_PASSWORD2 = "PjGPWNUgOYe6i1Ef";
  36. private $MYSQL_DB2 = "ctsdata";
  37. private $MYSQL_PORT2 = "3306";
  38. //Memcache配置
  39. private $MEMCACHE_HOST = "139.224.30.29";
  40. private $MEMCACHE_PORT = "11211";
  41. private $MEMCACHE_USER = "memcached";
  42. private $API_GPS_ACCOUNT = "15618818219";
  43. private $API_GPS_PASSWORD = "123456";
  44. /**
  45. * 链接正式数据库
  46. * @return PDO
  47. */
  48. function conn()
  49. {
  50. try {
  51. $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"));
  52. return $pdo;
  53. } catch (PDOException $e) {
  54. zzcsUtils::writeLog('new PDO failed:' . $e->getMessage());
  55. }
  56. }
  57. /**
  58. * 链接测试数据库
  59. * @return PDO
  60. */
  61. function conn_test()
  62. {
  63. try {
  64. $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"));
  65. return $pdo;
  66. } catch (PDOException $e) {
  67. zzcsUtils::writeLog('new PDO failed:' . $e->getMessage());
  68. }
  69. }
  70. /**
  71. * 链接waice数据库
  72. * @return PDO
  73. */
  74. function conn_waice()
  75. {
  76. try {
  77. $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"));
  78. return $pdo;
  79. } catch (PDOException $e) {
  80. zzcsUtils::writeLog('new PDO failed:' . $e->getMessage());
  81. }
  82. }
  83. /**
  84. * 添加缓存
  85. * @param $key
  86. * @param $value
  87. */
  88. public function set_memcache($key, $value)
  89. {
  90. $mem = new Memcache;
  91. $mem->connect($this->MEMCACHE_HOST, $this->MEMCACHE_PORT);
  92. $mem->set($key, $value);
  93. }
  94. /**
  95. * 获取内存中的数据
  96. * @param $key
  97. * @return array|string
  98. */
  99. public function get_memcache($key)
  100. {
  101. $mem = new Memcache;
  102. $mem->connect($this->MEMCACHE_HOST, $this->MEMCACHE_PORT);
  103. $value = $mem->get($key);
  104. return $value;
  105. }
  106. /**
  107. * 删除键值对应的数据
  108. * @param $key
  109. * @return bool
  110. */
  111. public function delete_memcache($key)
  112. {
  113. $mem = new Memcache;
  114. $mem->connect($this->MEMCACHE_HOST, $this->MEMCACHE_PORT);
  115. $value = $mem->delete($key);
  116. return $value;
  117. }
  118. }