cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[BUG]: Invalid parameter number when use db builder

Open borisdelev opened this issue 4 years ago • 4 comments

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 avatar Jan 14 '22 08:01 borisdelev

@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?

niden avatar Jan 14 '22 12:01 niden

It might be because of PDO

https://stackoverflow.com/questions/18028706/php-pdoexception-sqlstatehy093-invalid-parameter-number

niden avatar Jan 14 '22 12:01 niden

You need to enable \PDO::ATTR_EMULATE_PREPARES => true

https://github.com/phalcon/cphalcon/issues/15810#issuecomment-979136093

Jeckerson avatar Jan 14 '22 12:01 Jeckerson

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!

borisdelev avatar Jan 14 '22 13:01 borisdelev