美文网首页
Tp6使用field报错 [] operator not sup

Tp6使用field报错 [] operator not sup

作者: 润发周润发 | 来源:发表于2020-05-25 10:38 被阅读0次
    感觉一般情况下,都不会遇到这种情况。。只有我这种特殊的,才会遇到。。。。报错的地方Query.php
    public function fieldRaw(string $field)
        {
            $this->options['field'][] = new Raw($field);
    
            return $this;
        }
    
    
    [] operator not supported for strings的意思是 这货是字符串,不能使用[]操作符,经过一番调查,终于发现我在使用field之前,在别的地方使用了count方法(不是连贯操作。居然也会被影响到),使得field自动变成了 "*",于是引发了这个错误。
    // $this->options['field']的打印结果
    string(1) "*"
    

    解决办法:

    • 1. 把field放到count的前边。但是这个方法,会影响到count语句的查询效率
    • 2. 在count前边先设置一个field = '*',然后再filed一次,这样就不会影响到效率。 个屁,filed只能设定一回。后边那个不生效了。。还是用方法1吧

    相关文章

      网友评论

          本文标题:Tp6使用field报错 [] operator not sup

          本文链接:https://www.haomeiwen.com/subject/shweahtx.html