How to select on tables in 2 different databases?

Hello,

I`m recently started to work in a company who use ZF2, and i never used before, so i trying understand and learn how works.

I have this code:

$user = $this->getUserLogged();
$usersList = $user->company->usersList();

if ($this->params()->fromQuery('filter')) {
       $usersList = $usersList->where('name', 'like', '%' . $this->params()->fromQuery('filter') . '%')
               ->orWhere('username', 'like', '%' . $this->params()->fromQuery('filter') . '%');
 } 

in first two lines ia get the users from an specific company.
inside the if, i need return all users of that company, but i`m returning all users of database.

Some one please could help me to understand why getting all instead of the users to belong the specific company? Or how to do this in right way?

Solved changing the second line of IF, and creating a new WHERE

$usersList = $usersList
->where(‘name’, ‘like’, ‘%’ . $this->params()->fromQuery(‘filter’) . ‘%’)
->where(‘company_id’, $this->getUserLogged()->company->id);