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

Can query builder accept many many "WHERE"?

Can query builder accept many many "WHERE"? For example, can it work?

$builder->from('Robots')

foreach ($filter as $column => $value) {
    $builder->where("$column = $value");
}

Because I don't how many columns it the $filter



9.3k
Accepted
answer
edited Mar '16

Use this code, it will also prevent SQL injection

$builder->from('Robots')

foreach ($filter as $column => $value) {
    $builder->andWhere($column . ' = :' . $column ':', array($column => $value));
}

https://docs.phalcon.io/en/latest/api/Phalcon_Mvc_Model_Query_Builder.html