/**
  * execute this query
  * @return mixed
  */
 private function execute($sql)
 {
     if (!$this->link) {
         $this->connect();
     }
     $start = microtime(true);
     $error = '';
     $this->result = $this->link->query($sql);
     if (false === $this->result) {
         $error = implode(';', $this->link->errorInfo());
         writeLog($error . ': ' . $sql, 1);
         throw new DatabaseErrorException($error, $sql);
     }
     if (DEBUG > 0) {
         $this->queries[] = array(kataFunc::getLineInfo(), trim($sql), false !== $this->result ? $this->result->rowCount() : '', $error, microtime(true) - $start . 'sec');
     }
 }
 /**
  * execute this query
  * @return mixed
  */
 private function execute($sql)
 {
     if (!$this->isConnected()) {
         $this->connect();
     }
     $start = microtime(true);
     $this->result = mysql_query($sql, $this->link);
     if (false === $this->result) {
         switch (mysql_errno($this->link)) {
             case 1062:
                 throw new DatabaseDuplicateException(mysql_error($this->link));
                 break;
             default:
                 writeLog(mysql_error($this->link) . ': ' . $sql, 1);
                 throw new DatabaseErrorException(mysql_error($this->link), $sql);
                 break;
         }
     }
     if (DEBUG > 0) {
         $this->queries[] = array(kataFunc::getLineInfo(), trim($sql), mysql_affected_rows($this->link), mysql_error($this->link), microtime(true) - $start . 'sec');
     }
 }
 /**
  * execute this query
  * @return mixed
  */
 private function execute($sql)
 {
     if (!$this->link) {
         $this->connect();
     }
     $start = microtime(true);
     $this->result = mssql_query($sql, $this->link);
     if (false === $this->result) {
         $msg = mssql_get_last_message();
         //TODO another way would be to check @@ERROR for errors 2601/2627 which is ALSO language dependend *facepalm*
         if (stripos($msg, 'duplicate') !== false) {
             DatabaseDuplicateException($msg);
         } else {
             writeLog($msg . ': ' . $sql, 1);
             throw new DatabaseErrorException($msg, $sql);
         }
     }
     if (DEBUG > 0) {
         $this->queries[] = array(kataFunc::getLineInfo(), trim($sql), '', mssql_get_last_message(), microtime(true) - $start . 'sec');
     }
 }
 /**
  * execute this query
  * @return mixed
  */
 private function execute($sql)
 {
     if (!$this->link) {
         $this->connect();
     }
     $start = microtime(true);
     $error = 0;
     $this->result = $this->link->query($sql);
     if (false === $this->result) {
         writeLog($this->link->lastErrorMsg() . ': ' . $sql, 1);
         throw new DatabaseErrorException($this->link->lastErrorMsg());
     }
     if (DEBUG > 0) {
         $this->queries[] = array(kataFunc::getLineInfo(), trim($sql), $this->link->changes(), $this->link->lastErrorMsg(), microtime(true) - $start . 'sec');
     }
 }
 /**
  * set key only if the stored casToken equals our castoken (=key is unchanged)
  * @param float $casToken castoken previously obtained by readCas
  * @param string $id keyname
  * @param string $value keyvalue
  * @param integer $ttl time to live in seconds
  * @param string|bool $forceMethod method to use
  * @return boolean
  */
 public function compareAndSwap($casToken, $id, $value, $ttl = 0, $forceMethod = false)
 {
     if (DEBUG > 2) {
         $this->results[] = array(kataFunc::getLineInfo(), 'read', $id, '*caching off*', 0);
         return false;
     }
     $startTime = microtime(true);
     $this->initialize();
     $id = CACHE_IDENTIFIER . '-' . $id;
     if (false === $forceMethod) {
         $this->method = $this->defaultMethod;
     } else {
         $this->method = $forceMethod;
     }
     if (self::CM_MEMCACHED == $this->method) {
         $this->initMemcached(true);
         $r = $this->memcachedClass->cas($casToken, $id, $value, $ttl);
         $done = true;
         if ($r && $this->memcachedClass->getResultCode() == Memcached::RES_SUCCESS) {
             $done = true;
         }
         $done = false;
         if (DEBUG > 0) {
             $this->results[] = array(kataFunc::getLineInfo(), 'read', $id, $done ? 'swapped' : 'my data is stale', microtime(true) - $startTime);
         }
         return $done;
     }
     throw new Exception('ExtCacheUtil: compareAndSwap works only with memcache(d)');
 }
 function read($id, $forceMethod = false)
 {
     if (DEBUG > 2) {
         $this->results[] = array(kataFunc::getLineInfo(), 'read', $id, '*caching off*', 0);
         return false;
     }
     if ($this->useRequestCache && isset($this->requestCache[$id])) {
         $data = $this->requestCache[$id];
         if (DEBUG > 0) {
             $this->results[] = array(kataFunc::getLineInfo(), 'reqCache', $id, kataFunc::getValueInfo($data), 0);
         }
         return $data;
     }
     $startTime = microtime(true);
     $this->initialize();
     $data = $this->_read($id, $forceMethod);
     if (DEBUG > 0) {
         $this->results[] = array(kataFunc::getLineInfo(), 'read', $id, kataFunc::getValueInfo($data), microtime(true) - $startTime);
     }
     if ($this->useRequestCache) {
         $this->requestCache[$id] = $data;
     }
     return $data;
 }