Yii Framework Forum: Bind Params In Criteria - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Bind Params In Criteria Rate Topic: -----

#1 User is offline   Greno 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 03-April 13

Posted 29 July 2013 - 11:43 AM

When I have this code:
$criteria = new CDbCriteria();
    $criteria->with = array('tweTicketPriceLevels' => array('alias'=>'pl'));
    $criteria->condition = "(pl.start_timestamp - interval ':etz seconds') < (LOCALTIMESTAMP - interval ':stz seconds')";
    $criteria->addCondition("(pl.end_timestamp - interval ':etz seconds') >= (LOCALTIMESTAMP - interval ':stz seconds')");
    $criteria->addCondition('t.event_id = :eid');
    $criteria->addCondition('t.deleted IS NULL');
    $criteria->addCondition('pl.deleted IS NULL');
    $criteria->params = array(':etz' => (int)$etz, ':stz' => (int)$stz_offset, ':eid' => (int)$eid);
    
    return self::model()->findAll($criteria);


it write me the error: HY093: invalid parameter number, but when I write this:

$criteria = new CDbCriteria();
    $criteria->with = array('tweTicketPriceLevels' => array('alias'=>'pl'));
    $criteria->condition = "(pl.start_timestamp - interval '".$etz." seconds') < (LOCALTIMESTAMP - interval '".$stz_offset." seconds')";
    $criteria->addCondition("(pl.end_timestamp - interval ':etz seconds') >= (LOCALTIMESTAMP - interval ':stz seconds')");
    $criteria->addCondition('t.event_id = :eid');
    $criteria->addCondition('t.deleted IS NULL');
    $criteria->addCondition('pl.deleted IS NULL');
    $criteria->params = array(':eid' => (int)$eid);
    
    return self::model()->findAll($criteria);


it run without error. It is some bug, or it has some reason? I use postgresql database.
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,605
  • Joined: 17-January 09
  • Location:Russia

Posted 29 July 2013 - 03:21 PM

Your issue is that PDO that is used by Yii's AR can't handle 2 or more same named placeholders in a single query so you need to use :etz1, :etz2 etc. and then bind these to the same variable.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users