Executes a caching query.
public executeCacheQuery ( string $query, array $params, array $types, Doctrine\DBAL\Cache\QueryCacheProfile $qcp ) : Doctrine\DBAL\Driver\ResultStatement | ||
$query | string | The SQL query to execute. |
$params | array | The parameters to bind to the query, if any. |
$types | array | The types the previous parameters are in. |
$qcp | Doctrine\DBAL\Cache\QueryCacheProfile | The query cache profile. |
return | Doctrine\DBAL\Driver\ResultStatement |
/** * Execute a query. * * If a query is one of DESCRIBE, SELECT, or SHOW * then use <code>Connection::executeQuery</code> * otherwise pass it off to <code>Connection::executeUpdate</code> * * @param string $sql sql query string * @param int $limit limit the number of results * @param bool $useCache cache the query * @param int $cacheTime how long to cache the query for (in seconds) * @return object QueryFactoryResult */ public function Execute($sql, $limit = null, $useCache = false, $cacheTime = 0) { $sql = trim($sql); $commandType = strtolower(substr($sql, 0, 3)); if (!in_array($commandType, array('des', 'sel', 'sho'))) { return $this->conn->executeUpdate($sql); } if ($limit) { $sql .= ' LIMIT ' . (int) $limit; } $qcp = null; $resultClass = __NAMESPACE__ . '\\QueryFactoryResult'; if ($this->hasResultCache) { $qcp = new QueryCacheProfile($cacheTime, self::CACHE_KEY); $resultClass = __NAMESPACE__ . '\\CachedQueryFactoryResult'; } if ($useCache && $this->hasResultCache) { // @todo ArrayCache shouldn't count as a real cache for $useCache $stmt = $this->conn->executeCacheQuery($sql, array(), array(), $qcp); } else { $stmt = $this->conn->executeQuery($sql, array(), array(), $qcp); } $obj = new $resultClass($stmt); $obj->MoveNext(); return $obj; }