Yii Framework Forum: Cdbcommand binding array for SQL IN clause - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cdbcommand binding array for SQL IN clause Rate Topic: -----

#1 User is offline   vitman 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 09-April 12

Posted 01 June 2012 - 05:52 AM

I want to have something like
$some_values = array(1,2,3,4,5);
Yii::app()->getDb()->createCommand('SELECT x FROM y WHERE z in (:p1)')->bindValuesForInClause(':p1'=>$some_values)->queryAll();

0

#2 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 01 June 2012 - 06:26 AM

use findAll()
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#3 User is offline   vitman 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 09-April 12

Posted 01 June 2012 - 06:45 AM

View PostRajith R, on 01 June 2012 - 06:26 AM, said:

use findAll()

Not an answer.

I have some really huge queries with some IN clauses written on pure pl/sql.AR not a solution here.
0

#4 User is offline   alex-w 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 223
  • Joined: 25-November 10

Posted 01 June 2012 - 09:31 AM

If you can use the query builder, http://www.yiiframew...bCommand#where()-detail
0

#5 User is offline   yugene 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 513
  • Joined: 08-August 09

Posted 02 June 2012 - 12:38 AM

View Postvitman, on 01 June 2012 - 05:52 AM, said:

I want to have something like
$some_values = array(1,2,3,4,5);
Yii::app()->getDb()->createCommand('SELECT x FROM y WHERE z in (:p1)')->bindValuesForInClause(':p1'=>$some_values)->queryAll();



Maybe idea from Stackoverflow will be helpful.
0

#6 User is offline   vitman 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 09-April 12

Posted 04 June 2012 - 10:03 AM

Thanks for replies.

BUT is this will not be useful if yii will do it automatically?
0

#7 User is offline   Kostas Apazidis (KonApaz) 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,332
  • Joined: 21-February 11
  • Location:Greece

Posted 10 March 2014 - 06:47 AM

View Postvitman, on 04 June 2012 - 10:03 AM, said:

Thanks for replies.

BUT is this will not be useful if yii will do it automatically?



This functionallity included in Yii2
https://github.com/y...uery-builder.md
Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#8 User is offline   Arthbar 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 28-March 14

Posted 28 March 2014 - 06:40 AM

Having come across this problem a few times in my projects I have come-up with the following Yii work-around using CDbCriteria which is a little hacky, but gives the security of param count matching.

When applied to your example my code would be:

$some_values = array(1,2,3,4,5);
$criteria = new CDbCriteria();
$criteria->addInCondition('z',$some_values);

$sql = 'SELECT x FROM y WHERE '.$criteria->condition;
$command = Yii::app()->db->createCommand($sql);
$results = $command->queryAll(true, $criteria->params);

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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