Using
doctrine/common v2.9.0
doctrine/dbal v2.8.0
This is the offending code part:
$qb = $db->createQueryBuilder()
->select(...)
->from(...)
->leftJoin(...)
->where(...)
->orderBy(...)
->setMaxResults(1)
->setParameter('forum_id', ANNOUNCEMENT_FORUM_ID ?? 3);
$query = $db->executeCacheQuery($qb->execute(), $qb->getParameters(), $qb->getParameterTypes(), new \Doctrine\DBAL\Cache\QueryCacheProfile(60, 'announcement', null));
$announcement = $query->fetch();
dump($announcement);
I'm not sure what exactly to pass as 1st Parameter for $db->executeCacheQuery()
, because if i put $qb->execute()
there, as it wants me to pass a Statement, i get this error:
Recoverable fatal error: Object of class PDOStatement could not be converted to string in ...../vendor/doctrine/dbal/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php on line 102
Which is this part inside the QueryCacheProfile
class:
When i use $qb->getSQL()
instead, which is a string, i get this error:
Fatal error: Uncaught TypeError: Argument 1 passed to Doctrine\DBAL\Cache\ResultCacheStatement::__construct() must be an instance of Doctrine\DBAL\Driver\Statement, instance of PDOStatement given, called in ....
This is the doc example I followed: https://www.doctrine-project.org/projects/doctrine-dbal/en/2.8/reference/caching.html#caching
How do I manage to cache this query?