Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Return value of think\\db\\PDOConnection::pdoQuery() must be of the type array, bool returned in #468

Open
hannburglar opened this issue May 29, 2023 · 0 comments

Comments

@hannburglar
Copy link

hannburglar commented May 29, 2023

webman使用think-orm和think-cache
使用db的链式方法cache进行查询例如:
model::where([xxx,xxx])->cache(true,60)->find();
会报错

TypeError: Return value of think\\db\\PDOConnection::pdoQuery() must be of the type array, bool returned in ....

就是下面这个方法里面$data,当从缓存里面查询不到数据时候,变量值不只是null

/**
     * 执行查询 返回数据集
     * @access protected
     * @param BaseQuery $query  查询对象
     * @param mixed     $sql    sql指令
     * @param array     $bind   参数绑定
     * @param bool      $master 主库读取
     * @return array
     * @throws DbException
     */
    protected function pdoQuery(BaseQuery $query, $sql, array $bind = [], bool $master = null): array
    {
        // 分析查询表达式
        $query->parseOptions();

        if ($query->getOptions('cache')) {
            // 检查查询缓存
            $cacheItem = $this->parseCache($query, $query->getOptions('cache'));
            $key       = $cacheItem->getKey();

            $data = $this->cache->get($key);
           // 当从缓存里面查询不到数据时候,$data值不只是null,还可能是false,只判断null会造成报错
            if (null !== $data) {
                return $data;
            }
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant