Earlier we performed CRUD operation with yii's Gii generating tool. Now we'll perform CRUD without Gii.

We'll perform a complete CRUD operation here.

The name of our Yii2 folder is dbb.

We have created a database named student and a table inside it named child.

YII Creating database 1

Look at the above snapshot, this is our table's structure.


Database Configuration

To configure your database in Yii2, go to common/config/main-local.php file and write the name of your database.

We have written student as the name of our database.

  1. <?php   
  2. return [   
  3.     'components' => [   
  4.         'db' => [   
  5.             'class' => 'yii\db\Connection',   
  6.             'dsn' => 'mysql:host=localhost;dbname=student',   
  7.             'username' => 'root',   
  8.             'password' => 'mysql',   
  9.             'charset' => 'utf8',   
  10.        ],   
  11.         'mailer' => [   
  12.             'class' => 'yii\swiftmailer\Mailer',   
  13.             'viewPath' => '@common/mail',   
  14.             // send all mails to a file by default. You have to set   
  15.             // 'useFileTransport' to false and configure a transport   
  16.             // for the mailer to send real emails.   
  17.             'useFileTransport' => true,   
  18.         ],   
  19.     ],   
  20. ];