本文整理匯總了PHP中Doctrine\DBAL\Connection::executeCacheQuery方法的典型用法代碼示例。如果您正苦於以下問題:PHP Connection::executeCacheQuery方法的具體用法?PHP Connection::executeCacheQuery怎麽用?PHP Connection::executeCacheQuery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\DBAL\Connection
的用法示例。
在下文中一共展示了Connection::executeCacheQuery方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: Execute
/**
* 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;
}