Search code examples
phpnette

Call to a member function where() on array php


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

I have got problem with this code. Error is:

Call to a member function where() on array.


Solution

  • fetchAll return ISelection. You dont call Where on ISelection

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

    or

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