duandian2725 2018-10-10 18:13
浏览 33

executeCacheQuery第一个参数想要Statement和string吗?

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:

enter image description here

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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分