Facebook
From S, 9 Years ago, written in PHP.
Embed
Download Paste or View Raw
Hits: 524
  1. public function findAllByIds($ids) {
  2.                 $inQuery = implode(',', array_fill(0, count($ids), '?'));
  3.                
  4.                 $query = ('
  5.                                         select
  6.                                                 src.id as id,
  7.                                                 src.name as name,
  8.                                                 src.description as description,
  9.                                                 src.website as website
  10.                                         from sources src
  11.                                         where
  12.                                                 src.is_active = 1
  13.                                                 and src.id in (' . $inQuery . ')
  14.                                 ');
  15.                                
  16.                 $command = Yii::app()->db->createCommand($query);
  17.                 foreach ($ids as $k => $id) {
  18.                         $command->bindValue(($k+1), $id);
  19.                 }      
  20.                 $result = $command->queryAll();
  21.                
  22.                 return $result;
  23.         }