We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to search data in two phalcon tables?? help me please

Someone could explain me How to search data in two phalcon tables:

I have this query:

   $Q = $this->request->getPost("data");

    $phql = 'SELECT b.idbank,b.name,m.description,m.date 

FROM bank b
inner join movement m on b.idbank=m.idbank
WHERE b.estado = 1 and b.name like "%'.$Q.'%" or m.description like "%'.$Q.'%"
Order by b.idbank desc ';

   $bank = $this->modelsManager->executeQuery($phql);

There would be some way to do it this way:

 $Q = $this->request->getPost("data");

$bank = Bank::find( [ "name like '%:dato:%'", "bind" => [ "dato" => $Q ] ] ); $mov = $bank->getmovement( [ "description like '%:dato:%'", "bind" => [ "dato" => $Q ] ] ); $bank = $mov->bank;

I actually do not know how to do it.

What I did is not working for me.

Some help would be important to me. thank.

But first way is correct one, what's problem with it? You can either use PHQL(query builder) or work on models. But the first is much better.

How to avoid sql injections with that ?? With the first it is much easier to inject sql

edited Mar '17

By using named parameters. I would suggest using query builder. Just check docs :)