public static function getHost() { if (empty($_SERVER['HTTP_HOST'])) { KC_LOG_WARNING('Unkown http host.'); $httpHost = 'localhost'; } else { $httpHost = $_SERVER['HTTP_HOST']; } self::$httpHost = $httpHost; return $httpHost; }
public function escapeString($strVal, $throw = true) { $this->getConnection($throw); $ret = self::$_dbObj->escapeString($strVal); if (false === $ret) { $errInfo = self::$_dbObj->getError(); if (true === $throw) { throw new Exception('database ' . __FUNCTION__ . ' failed [ error info: ' . $errInfo['errmsg'] . ", str: {$strVal} ]."); } else { if (!empty($throw)) { throw new Exception('database ' . $throw . ' failed [ error info: ' . $errInfo['errmsg'] . ", str: {$strVal} ].", 1); } } KC_LOG_WARNING("escape string failed [ str: {$strVal} ]."); return $ret; } return $ret; }
/** * * 转义一个字符串 * @param string $strVal 要转义的字符串 */ public function escapeString($strVal) { if (!$this->_isConnected) { KC_LOG_WARNING(__FUNCTION__ . " failed, db has not been connected [ strVal: {$strVal} ]."); return false; } return $this->_mysqli->escape_string($strVal); }
/** * 原子增加一个 */ public function setIncr($key, $timeout = 0) { $retry = 0; $ret = false; do { $this->getConnection($retry !== 0); try { $ret = $this->_redisObj->incr($key); if ($timeout) { $this->_redisObj->expire($key, $timeout); } break; } catch (Exception $ex) { KC_LOG_WARNING('try to set expire redis returned false [ times: %s ].', $retry); sleep(1); } } while ($retry++ < Conf::$redisRetry); if (false === $ret) { throw new Exception('query redis to get all failed.'); } return $ret; }