I'm new to Yii, and experimenting with yii2's createCommand(), for this I've to create a new instance of the class yii\db\connection,
Here is an action in my controller,
public function actionDues($student_id){
$connection = new \yii\db\Connection([
'dsn' => 'mysql:host=localhost;dbname=db_school',
'username' => 'root',
'password' => '',
'enableSchemaCache' => true,
]);
$sql = 'select * from group_fees where group_id in (select group_id from group_subscriptions where subscriber_id='.$student_id.')';
$command = $connection->createCommand($sql)->queryAll();
}
Am I right in thinking that there must be a connection instance already loaded, which I can use, instead of creating a new instance of the yii\db\connection class as above?