如何在symfony2中使用apc case doctrine准备查询

时间:2014-01-10 05:34:12

标签: symfony doctrine apc

我在symfony2中使用了后续查询我需要APC缓存与doctrine如何使用它...我尝试按照apc缓存但没有得到错误。

$query =  $this->getDoctrine()->getEntityManager()->getConnection()->prepare(
        "SELECT  V.id,
            (CASE WHEN "DAY"      THEN DATE_ADD( NOW() , INTERVAL start_date DAY ) 
                  WHEN "MONTH"    THEN DATE_ADD( NOW() , INTERVAL start_date MONTH )
                  WHEN "YEAR"     THEN DATE_ADD( NOW() , INTERVAL start_date YEAR ) 
             END as startDate
            ) `enter code here`
        FROM table_name V

         WHERE V.id = :id 
         ORDER BY date ASC"
    );
 $query->bindValue('id', $id)
 $query->setResultCacheDriver(new ApcCache())
 $query->useResultCache(true, 300, 'testcache');
 $query->execute();   
 $results = $query->fetchAll(); 

1 个答案:

答案 0 :(得分:1)

use Doctrine\ORM\Query\ResultSetMapping;

$oResultSetMapp = new ResultSetMapping;
$oResultSetMapp->addScalarResult('id', 'id');
$oResultSetMapp->addScalarResult('name', 'name');

$sqlQuery = "SELECT T.id AS id, T.enable, T.name
    FROM table_name as T
    WHERE T.enable =  :enable";

$query = $this->getDoctrine()->getEntityManager()
        ->createNativeQuery($sqlQuery, $oResultSetMapp)
        ->setParameter('enable', 1) 
        ->setResultCacheDriver(new ApcCache())
        ->useResultCache(true, 300, 'testcache');
$query->getResult();

试试这个,这对你有帮助。