From [[https://www.youtube.com/watch?v=niOtgKNWfiU|Yii2 Lesson - 4 Connecting to a DB and Active Records]]\\

Create a database and then a table called 'users' with the following columns\\
<code>
CREATE TABLE `users` (
  `user_id` int(11) NOT NULL,
  `username` varchar(100) NOT NULL,
  `password` int(32) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
</code>

Modify the ''config/db.php'' file to point to the database with correct user\\

Then create a ''Users.php'' in the ''models'' directory with
<code>
<?php

namespace app\models;

use yii\db\ActiveRecord;

 class Users extends ActiveRecord
 {

 }
</code>

Then in ''controllers'' folder create a ''UsersController.php'' file\\
<code>
<?php

namespace app\controllers;

use yii\web\Controller;
use app\models\Users;

class UsersController extends Controller
{
 public function actionIndex()
 {
  echo "Testing";
 }
}
</code> 

Then if you call up the ''http://localhost/basic/web/index.php?r=users/index'', you will see the words ''Testing'' on the page\\ 

Next replace the "Testing" code with
<code>
  $users = Users::find()->all();
  print_r($users);
</code>

Refresh the webpage and you should see a ''print_r'' output for the database values.\\

Replace the ''print_r'' with
<code>
return $this->render('index',['users'=>$users]);
</code>

Go to the ''views'' folder and create a folder ''users''\\
Make a new file in the folder ''index.php'' with\\
<code>
<?php

foreach($users as $user)
{
 echo $user->username.'<br/>';
}
</code>

Calling the webpage will now show the ''username'' data.

