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

Bind parameters using array

Hi all,

On the documentation https://docs.phalcon.io/en/latest/reference/models.html It says:

Both find() and findFirst() methods accept an associative array specifying the search criteria:

I was wondering if the first example does the binding automatically or not.

$robot = Robots::findFirst(array(
    "type = 'virtual'",
    "order" => "name DESC",
    "limit" => 30
));

$robots = Robots::find(array(
    "conditions" => "type = ?1",
    "bind"       => array(1 => "virtual")
));

Thank you



34.6k
Accepted
answer
edited Apr '15

No, the first example does not use bound parameters, but as it's a constant-known value and there's no risk of sql injection.

Hi, example of using bind parameters in findFirst metod:

$user = User::findFirst(array(
    'username = :username:', 
    'bind' => array('username' => $username)
))
edited Apr '15

yep, sorry guys, I didn't see the real interface type ="virtual", as a string and I though it was an array of conditions. Thank you!