InterviewSolution
| 1. |
List Some Database Related Functions In Yii 2 Framework? |
|
Answer» Below are LIST of some database related functions used in Yii 2 Framework find(): Creates an yii dbActive QueryInterface instance for query purpose. Usages: //Getting first record matching with condition $user = User::find()->where(['name' => 'Abc'])->one(); Find All(): Returns a list of active record models that match the specified primary key value(s) or a set of column values. Usages: // find the CUSTOMERS whose primary key value is 10 $customers = Customer::find All (10); // find customers whose age is 30 and whose status is active $customers = Customer::find All (['age' => 30, 'status' => 'active']); INSERT (): Inserts a row into the associated database table using the attribute values of this record. Usages: $customer = new Customer; $customer->name = $name; $customer->email = $email; $customer->insert(); Delete(): Deletes the table row corresponding to this active record. Usages: $models = Customer::find()->where('status = 3')->all(); foreach ($models as $model) { $model->delete(); } Delete All(): Deletes rows in the table using the provided conditions. Usages: Customer::delete All ('status = 3'); save() :SAVES the current record. Usages: $customer = new Customer; // or $customer = Customer::find One ($id); $customer->name = $name; $customer->email = $email; $customer->save(); Below are list of some database related functions used in Yii 2 Framework find(): Creates an yii dbActive QueryInterface instance for query purpose. Usages: //Getting first record matching with condition $user = User::find()->where(['name' => 'Abc'])->one(); Find All(): Returns a list of active record models that match the specified primary key value(s) or a set of column values. Usages: // find the customers whose primary key value is 10 $customers = Customer::find All (10); // find customers whose age is 30 and whose status is active $customers = Customer::find All (['age' => 30, 'status' => 'active']); Insert (): Inserts a row into the associated database table using the attribute values of this record. Usages: $customer = new Customer; $customer->name = $name; $customer->email = $email; $customer->insert(); Delete(): Deletes the table row corresponding to this active record. Usages: $models = Customer::find()->where('status = 3')->all(); foreach ($models as $model) { $model->delete(); } Delete All(): Deletes rows in the table using the provided conditions. Usages: Customer::delete All ('status = 3'); save() :Saves the current record. Usages: $customer = new Customer; // or $customer = Customer::find One ($id); $customer->name = $name; $customer->email = $email; $customer->save(); |
|