Closed
Description
Phalcon\Mvc\Model\Query\Builder error if using mixed integer and string placeholder. It only happen when the integer placeholder is not starting from zero.
In my case I added the string placeholder using andWhere. The sql output: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
After I debuged, It turns out that the array keys of the integer placeholder in __bindParams has changed.
Example in my project:
Before andWhere
$builder->getQuery() attributes:
_phql = SELECT ai.*, ad.* FROM [BI\Models\Adindex] AS [ai] JOIN [BI\Models\Ad] AS [ad] ON ad.id=ai.ad_id WHERE (ai.adcat_parent = ?1 AND ai.status = ?2) AND (ai.ad_kind=1) ORDER BY id DESC
_bindParams = [ 1=>2, 2=>1 ]
after $builder->andWhere('ad.price >= :minprice:', ['minprice'=>$x['minprice']]);
$builder->getQuery() attributes become:
_phql = SELECT ai.*, ad.* FROM [BI\Models\Adindex] AS [ai] JOIN [BI\Models\Ad] AS [ad] ON ad.id=ai.ad_id WHERE ((ai.adcat_parent = ?1 AND ai.status = ?2) AND (ai.ad_kind=1)) AND (ad.price >= :minprice:) ORDER BY id DESC
_bindParams = [ 0=>2, 1=>1, 'minprice' => '70000000' ]
Notice that the _bindParams keys has changed
Metadata
Assignees
Labels
No labels