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

ORM: Invalid parameter of numbers

Hello! Have a little problem with my query to database. My code:

try {
                $products_update = Products::query()
                    ->where("parent_id = :parent_id:")
                    ->where("position >= :newIndex:")
                    ->where("position < :oldIndex:")
                    ->bind(array(
                        "parent_id" => $product->parent_id,
                        "newIndex" => $sort->newIndex,
                        "oldIndex" => $sort->oldIndex
                        ))
                    ->execute();
                } catch (\Exception $e)
                {
                    echo $e;
                }

And I get the error:

Invalid parameter number: number of bound variables does not match number of tokens

But I can't understand what parameter I didn't bind. Please, help. Thank you very much!



93.7k
Accepted
answer

Instead of:

->where("parent_id = :parent_id:")
->where("position >= :newIndex:")
->where("position < :oldIndex:")

use

->where("parent_id = :parent_id:")
->andWhere("position >= :newIndex:")
->andWhere("position < :oldIndex:")

Oh, Nikolay, thank you veru much! So stupid mistake :(

Also you could just write:

->where("parent_id = :parent_id: AND position >= :newIndex: AND position < :oldIndex:")

Also i think better to use find/findFirst instead of modelManager(query returns modelsManager).

Also you could just write:

->where("parent_id = :parent_id: AND position >= :newIndex: AND position < :oldIndex:")

Also i think better to use find/findFirst instead of modelManager(query returns modelsManager).

Thank's for advice! I'm a newbie to Phalcon, and sometimes when one method lacks (by my mistake, of course), I look for other in documentation. In that time Phalcon gave me error after using "find", and I use "query".

I'll do better in the future :)