when i use construct in model it give me this error.
ErrorException
Undefined variable: db [url=https://www.google.com/search?q=ErrorException+Undefined+variable%3A+db][/url]
Model:
<?php namespace App\Models;
use CodeIgniter\Model;
use CodeIgniter\Database\ConnectionInterface;
class My_model extends Model {
protected $db;
public function __construct()
{
parent::__construct();
$db = \Config\Database::connect();
}
public function get_allnames() {
$query = $db->query('SELECT A.* tbl_products');
$results = $query->getResultArray();
return $results;
}
}
Iam i doing it wrong?