本文整理汇总了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;
}