SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

Hey,

i get, if i use to bind a variable to a placeholder at Prepared Statements everytime this Error:

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

I have looked after helpful information which can solve this Problem, but i didnt't find anything. And if i find something, this didnt't solved this problem.

If i debug my Code at the Parameters are the value of the Parameter in the url like "Ha". The Error is showing at the DB-Query.

My Code:

                    $name = $this->request->get("name");

                    $parameters = [
                        "name" => $name
                    ];



                    $foundedNames = Name::findFirst(
                        [
                            "name LIKE ' % :name: % ' ",
                            "bind" => $parameters
                        ]
                    );

I hope you can help me at solve this Problem.

Conner

Just do it like:

  $parameters = [
                    "name" => "%{$name}%"
                ];

$foundedNames = Name::findFirst(
                    [
                        "name LIKE :name:",
                        "bind" => $parameters
                    ]
                );

To further explain - you cannot put a bound parameter in a like statement, surrounded by '%' - the sql compiler doesn't like that. So, you need to add the '%' to the value that gets bound.