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.

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!



66.0k
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("parentid = :parentid: 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("parentid = :parentid: 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 :)