List Of Query Commands for getting Data from database

Get Single Record.

1. ModelName::model()->findByPk($primaryKey);
2. ModelName::model()->findByAttributes(array(‘columnName1’=>$value1, ‘columnName2’=>$value2));
3. ModelName::model()->find(array(‘condition’=>’columnName1=’.$value1. ‘ and columnName2=’.$value2));
4. Yii::app()->user->db->createCommand()
->select(‘*’)
->from(‘tableName’)
->where(‘columnName1=’.$value1.’ and columnName2=’.$value2)
->queryRow();

Get Last Single Record.

1. ModelName::model()->findByAttributes(array(‘columnName1’=>$value1, ‘columnName2’=>$value2,array(‘order’=>’Auto_Increment_ID desc’)));
2. ModelName::model()->find(array(‘condition’=>’columnName1=’.$value1.’ and columnName2=’.$value2,  ‘order’=>’auto_Increment_ID desc’));
3. Yii::app()->user->db->createCommand()
->select(‘*’)
->from(‘tableName’)
->where(‘columnName1=’.$value1.’ and columnName2=’.$value2.’ order by auto_Increment_ID’)
->queryRow();

Get Multiple Records.

1. ModelName::model()->findAll(array(‘condition’=>’columnName1=’.$value1.’ and columnName2=’.$value2));
2. ModelName::model()->findAll(‘columnName1=’.$value1.’ and columnName2=’.$value2);
3. ModelName::model()->findAllByAttributes(array(‘columnName1’=>$value1,’columnName2’=>$value2));
4. ModelName::model()->findAllByAttributes(array(‘columnName1’=>$value1,’columnName2’=>$value2),
$condition= ‘columnName3 <> :aliasName3 AND columnName4 >= :aliasName4 OR columnName5 = :aliasName5’,
$params =array(
‘:aliasName3’ => $value3,
‘:aliasName4’ => $value4,
‘:aliasName5’ => $value5,
));
5. Yii::app()->user->db->createCommand()
->select(‘*’)
->from(‘tableName’)
->where(‘columnName1=’.$value1.’ and columnName2=’.$value2)
->queryAll();

Advertisements

One comment

  1. Excellent way of describing, and nice paragraph to get information regarding my presentation subject, which i am going to deliver
    in academy.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s