Repository navigation
dbConnection
Corey Avis edited this page Sep 23, 2026
·
2 revisions
Initializes the MySQL connection. Manual execution is only required if the database name was omitted during instantiation; otherwise, the connection is established automatically via the constructor.
dbConnection(?string $dbname, ?string $dbuser, ?string $dbpass, ?string $dbhost): static
dbname (?string) : The name of the database to establish a connection with.
dbuser (?string) : The database username. ^(optional)^
dbpass (?string) : The database password. ^(optional)^
dbhost (?string) : The database host name. ^(optional)^
dbuser,dbpassanddbhostare optional because there are default values already set within the configuration that you can use.
(static) : Returns the current instance to allow for method chaining.
$db->dbConnection('mydb', 'username', 'password', 'localhost');
| Config Key | Default Value | Allowed Values | Description |
|---|---|---|---|
| db.host | localhost | string | Database host name |
| db.name | null | string | Database name |
| db.user | root | string | Database username |
| db.pass | root | string | Database password |
- Throws an exception if database name, username, password or host are not specified.
- Throws an exception if the connection fails.
Home | CoreyDB | Environment