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.

SQLSTATE[HY093]: Invalid parameter number

I get error Exception: SQLSTATE[HY093]: Invalid parameter number on phalcon

    $phql = "SELECT Matches.* FROM \Api\Model\Matches as Matches
    WHERE (Matches.user1_id = :user1_id: AND Matches.user2_id = :user2_id:) OR (Matches.user1_id = :user2_id: AND Matches.user2_id = :user1_id:)";
    $rows = $this->modelsManager->executeQuery($phql, [
        "user1_id"    => $user1_id,
        "user2_id"    => $user2_id
    ]);

but it works:

    $phql = "SELECT Matches.* FROM \Api\Model\Matches as Matches
      WHERE (Matches.user1_id = :user1_id: AND Matches.user2_id = :user2_id:) OR (Matches.user1_id = :user3_id: AND Matches.user2_id = :user4_id:)";
      $rows = $this->modelsManager->executeQuery($phql, [
            "user1_id"    => $user1_id,
            "user2_id"    => $user2_id,
            "user3_id"    => $user1_id,
            "user4_id"    => $user2_id
      ]);

Phalcon Version: 3.2.0

PHP Version: 7.1.5

Is this normal behavior or not? Thank you.

edited 17d ago

That's not a best way to tackle your query - it's error prone and it's not DRY. You'd better use IN caluse in this case.

$builder->inWhere("id", [1, 2, 3]);
public inWhere (mixed $expr, array $values, [mixed $operator])

Appends an IN condition to the current WHERE conditions

https://docs.phalconphp.com/en/latest/api/Phalcon%5FMvc%5FModel%5FQuery%5FBuilder