Any time you open up a model in CodeIgniter it sets the $db see below Model constructor.
PHP Code:
/**
* Model constructor.
*
* @param ConnectionInterface|null $db
* @param ValidationInterface|null $validation
*/
public function __construct(ConnectionInterface &$db = null, ValidationInterface $validation = null)
{
$db = $db ?? Database::connect($this->DBGroup);
$this->db = &$db;
$this->tempReturnType = $this->returnType;
$this->tempUseSoftDeletes = $this->useSoftDeletes;
$this->tempAllowCallbacks = $this->allowCallbacks;
$this->validation = $validation ?? Services::validation(null, false);
}
You can also connect like so:
PHP Code:
// The long way.
$db = \Config\Database::connect($groupName);
// helper way
$db = db_connect($groupName);
Nothing really confusing about it.
Even if you use a Model the $this->db is there along with QueryBuilder.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )