User::find ()->all (); Returns all user data;
User::findone ($id); Returns a data of the primary key id=1;
User::find ()->where ([' Name ' => ' TTT '])->one (); Returns a piece of data [' name ' => ' TTT '];
User::find ()->where ([' Name ' => ' TTT '])->all (); Returns all data of [' Name ' => ' TTT '];
User::findbysql (' SELECT * from user ')->all (); Use SQL statements to query all data in the user table;
User::findbysql (' SELECT * from user ')->one (); This method uses SQL statements to query a data in the user table;
User::find ()->andwhere ([' Sex ' => ' female ', ' age ' => '])->count (' id '); (a) Statistics of the total number of eligible articles;
User::find ()->one (); Returns a piece of data;
User::find ()->all (); return all data;
User::find ()->count (); Returns the number of records;
User::find ()->average (); Returns the average of the specified column;
User::find ()->min (); Returns the minimum value of the specified column;
User::find ()->max (); Returns the maximum value of the specified column;
User::find ()->scalar (); Returns the query result of the first row of the value;
User::find ()->column (); Returns the value of the first column in the query result;
User::find ()->exists (); Returns a value indicating whether a row of data is included in the query result;
Query action:
User::find ()->where ([' Name ' => ' username '])->one (); This method returns a piece of data [' name ' => ' username '];
User::find ()->where ([' Name ' => ' username '])->all (); This method returns all data for [' Name ' => ' username '];
User::find ()->andwhere ([' Sex ' => ' man ', ' age ' => '])->count (' id '); (a) Statistics of the total number of eligible articles;
New action:
$model = NewUser ();
$model->username = ' username ';
$model->age = ' 20 ';
$model->insert ();
To modify an operation:
$User = User::findone ($id);
$User->name = ' Zhangsan ';
$User->save (); Equivalent to $User->update ();
Delete action:
User::d eleteall (' name = Username '); Deletes the data of name = Username;
User::findone ($id)->delete (); Deletes a database with a primary key of $id variable value;
User::d eleteall (' Age >: Age and sex =: Sex ', [': Age ' => ', ': Sex ' => ' 1 ']); Delete the eligible data;
The above is a small set to introduce the YII2 framework database simple additions and deletions to check grammar summary, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!