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; } }