调用成员函数where()在数组php上

时间:2018-02-02 19:32:30

标签: php nette

        $customers = \dibi::select('*')->from('accounts')->fetchAll();
    if($username){
        $customers = $customers->where("username", $username);
    }

我遇到了这段代码的问题。错误是:

  

调用成员函数where()on array。

1 个答案:

答案 0 :(得分:1)

fetchAll返回ISelection。你不会在ISelection上调用Where

if($username){
  $customers = \dibi::select('*')->from('accounts')->where("username", $username)->fetchAll();
}

$customersTable = \dibi::select('*')->from('accounts');

if($username){
  $customersTable = \dibi::select('*')->from('accounts')->where("username", $username);
}

$customers = $customersTable->fetchAll();