I want to execute some query in Views/login.php I have created database connection in Controller, but i need to execute some sort of queries in Views. Not able to access it by $this->db->query("") in views, What is the good solution?
Note as DFriend mentionned in the comment of this question, this is a bad practice in an MVC pattern. Queries should always be runned in Models that passed data to the Controller which displays those data in Views.
However if you really want to execute a query into one view you have to initiate your database object before running queries.
$this->db
does not exist in your case because your view does not extend a class that has a parameter callled $db
<?php
$db = db_connect();
$query = $db->query('YOUR QUERY');
//you get result as an array in here but fetch your result however you feel to
$result = $query->getResultArray();
?>
Here you create a database connection, then you run your query with the db object your created.