Tuesday, September 30, 2014

Multiple database in yii


'db'=>array(
   'connectionString' => 'mysql:host=localhost;dbname=test',
   'emulatePrepare' => true,
   'username' => 'test',
    'class'=>'CDbConnection',
   'password' => 'test@2014test',
   'charset' => 'utf8',
  ),



'db2'=>array( 
   'connectionString' => 'mysql:host=localhost;dbname=*****net',
   'emulatePrepare' => true,
   'username' => '*****net',
   'password' => '*******',
    'class'=>'CDbConnection',
   'charset' => 'utf8', 
  ),


Call function at CGridView in yii

 array(
                'header'=>'client',
                'type'=>'raw',
                'value'=>'$data->getClientinformation($data->client_id)',
  'filter'=>$model->getClientinfilter(),
            ),
public function getClientinformation($client_id){
 $user = Yii::app()->db2->createCommand()
    ->select('name')
    ->from('client')
    ->where('id=:id', array(':id'=>$client_id))
 ->queryAll();
 return $user[0]['name'];

  }


public function getClientinfilter(){
   
 // return 'jibon';
  
  $command = Yii::app()->db2->createCommand();
  $userArray = $command->select('id, name')->from('client')->order('name')->queryAll();
  return CHtml::dropdownlist('GalleryBooking[client_id]','',CHtml::listData($userArray,'id','name'), array('empty' => ''));

  
  }