Example #1
0
	/**
	* Increment a key in the keystore by the given value. If the key does not exist, it will be set to $value. An existing key's value will be treated as an int so this may destroy existing string data if used improperly
	*
	* @param string $key key to increment
	* @param int $value new value
	* @throws Interspire_KeyStore_Exception
	*/
	public function increment($key, $value = 1)
	{
		$query = "INSERT INTO `[|PREFIX|]keystore` (`key`, `value`) VALUES ('" . $this->db->Quote($key) . "', '" . $value . "') ON DUPLICATE KEY UPDATE `value` = CAST(`value` AS SIGNED) + VALUES(`value`)";
		$result = $this->db->Query($query);
		if (!$result) {
			throw new Interspire_KeyStore_Exception($this->db->GetErrorMsg());
		}

		return (int)$this->get($key);
	}