Welcome Guest, Not a member yet? Register   Sign In
$db is confusing in the docs.
#5

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 nullValidationInterface $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(nullfalse);
    } 

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 )
Reply


Messages In This Thread
$db is confusing in the docs. - by blaasvaer - 12-06-2020, 04:33 AM
RE: $db is confusing in the docs. - by blaasvaer - 12-06-2020, 10:37 AM
RE: $db is confusing in the docs. - by InsiteFX - 12-06-2020, 12:35 PM



Theme © iAndrew 2016 - Forum software by © MyBB