[BUG]: Invalid parameter number when use db builder
Hello :) Live long Phalcon!
Describe the bug Its so ease to reproduce and its about Query Builder. The issue is related with parameters and query, see the code below.
To Reproduce Use any table or whatever... when i use same binded param error ocured. Just example:
$builder = $this->modelsManager->createBuilder();
$builder->addFrom('Models\Articles');
$builder->where('id={id:int} OR id={id:int}', ['id' => 1]);
$builder->getQuery()->execute();
This will return me an error: PDOException: SQLSTATE[HY093]: Invalid parameter number. If i remove the second {id:int} for example- will work.
Expected behavior Well... to can reuse same param in query
Details
- Phalcon version: 5.0.0beta2
- PHP Version: 8.0.6
- Operating System: Windows
- Server: Apache
@borisdelev I saw that the other day on a personal project. I don't remember doing anything to the PHQL code to produce the above. I am wondering if this is a SQL issue?
@Jeckerson thoughts?
It might be because of PDO
https://stackoverflow.com/questions/18028706/php-pdoexception-sqlstatehy093-invalid-parameter-number
You need to enable \PDO::ATTR_EMULATE_PREPARES => true
https://github.com/phalcon/cphalcon/issues/15810#issuecomment-979136093
Worked! Maybe it is a good idea that to be mention in documentation... anyway. Thank you @Jeckerson , @niden ! U are the best :)
Hope soon i can help u more with Phalcon 6. Peace!