Wednesday, December 16, 2015

Yii2 DB query using model class

echo $query->createCommand()->sql;
$query->createCommand()->getRawSql()


Add Record:
$model = new Products();
$model->name = 'Light';
$model->color = 'White';
$model->created_date = date('Y-m-d H:m:s');
$model->save();   // Return TRUE or FALSE.
echo $model->id; // Return id for created record.

Update Record:
$model = Products::findOne($id);
$model->name = 'Light';
$model->color = 'White';
$model->created_date = date('Y-m-d H:m:s');
$model->save();   // Return TRUE or FALSE.

Delete Record:
$model = Products::findOne($id);
$model->delete();   // Return TRUE or FALSE;

Products::deleteAll(['color'=>'red']);  // Delete multiple record with condition.

Select Record:
UserEvents::find()->select(['user_events.id', "CONCAT(year, '', month) AS yearmonth", 'location', 'budget_id', 'year', 'month', 'day', 'no_of_guests', 'event_id'])->where(['user_id'=>$bride_id])->andWhere('id != '.$id)->andWhere('"yearmonth" >= :year_month', [':year_month'=>$year_month])->joinWith('budget_master')->joinWith('guest_master')->joinWith('event_type_master')->asArray()->all();

Learn JavaScript - String and its methods - 16

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>String and it's methods - JS&l...