Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Bind parameters using array

Hi all,

On the documentation http://docs.phalconphp.com/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



33.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!