Craft 3 Class Reference

Class craft\config\DbConfig

Inheritance
craft\config\DbConfig ยป yii\base\BaseObject
Implements
yii\base\Configurable
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/config/DbConfig.php

DB config class

Public Properties
Property Type Description Defined By
$attributes array An array of key => value pairs of PDO attributes to pass into the PDO constructor. craft\config\DbConfig
$charset string The charset to use when creating tables. craft\config\DbConfig
$database string The name of the database to select. craft\config\DbConfig
$driver string The database driver to use. craft\config\DbConfig
$dsn string If you want to manually specify your PDO DSN connection string you can do so here. craft\config\DbConfig
$password string The database password to connect with. craft\config\DbConfig
$port integer The database server port. craft\config\DbConfig
$schema string The database schema to use (PostgreSQL only). craft\config\DbConfig
$server string The database server name or IP address. craft\config\DbConfig
$tablePrefix string If you're sharing Craft installs in a single database (MySQL) or a single database and using a shared schema (PostgreSQL), then you can set a table prefix here to avoid table naming conflicts per install. craft\config\DbConfig
$unixSocket string, null MySQL only. craft\config\DbConfig
$url string, null The database connection URL, if one was provided by your hosting environment. craft\config\DbConfig
$user string The database username to connect with. craft\config\DbConfig
Public Methods
Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. craft\config\DbConfig
updateDsn() Updates the DSN string based on the config setting values. craft\config\DbConfig
Constants
Constant Value Description Defined By
DRIVER_MYSQL 'mysql' craft\config\DbConfig
DRIVER_PGSQL 'pgsql' craft\config\DbConfig

Property Details

$attributes public property #

An array of key => value pairs of PDO attributes to pass into the PDO constructor. For example, when using the MySQL PDO driver (https://secure.php.net/manual/en/ref.pdo-mysql.php), if you wanted to enable a SSL database connection (assuming SSL is enabled in MySQL (https://dev.mysql.com/doc/refman/5.5/en/using-secure-connections.html) and 'user' can connect via SSL, you'd set these:

[
    PDO::MYSQL_ATTR_SSL_KEY    => '/path/to/my/client-key.pem',
    PDO::MYSQL_ATTR_SSL_CERT   => '/path/to/my/client-cert.pem',
    PDO::MYSQL_ATTR_SSL_CA     => '/path/to/my/ca-cert.pem',
],
public array $attributes = []

$charset public property #

The charset to use when creating tables.

public string $charset 'utf8'

$database public property #

The name of the database to select.

public string $database ''

$driver public property #

The database driver to use. Either 'mysql' for MySQL or 'pgsql' for PostgreSQL.

public string $driver self::DRIVER_MYSQL

$dsn public property #

If you want to manually specify your PDO DSN connection string you can do so here.

public string $dsn null

$password public property #

The database password to connect with.

public string $password ''

$port public property #

The database server port. Defaults to 3306 for MySQL and 5432 for PostgreSQL.

public integer $port null

$schema public property #

The database schema to use (PostgreSQL only).

See also https://www.postgresql.org/docs/8.2/static/ddl-schemas.html.

public string $schema 'public'

$server public property #

The database server name or IP address. Usually 'localhost' or '127.0.0.1'.

public string $server 'localhost'

$tablePrefix public property #

If you're sharing Craft installs in a single database (MySQL) or a single database and using a shared schema (PostgreSQL), then you can set a table prefix here to avoid table naming conflicts per install. This can be no more than 5 characters, and must be all lowercase.

public string $tablePrefix ''

$unixSocket public property #

MySQL only. If this is set, then the CLI connection string (used for yiic) will connect to the Unix socket, instead of the server and port. If this is specified, then 'server' and 'port' settings are ignored.

public string, null $unixSocket null

$url public property #

The database connection URL, if one was provided by your hosting environment. If this is set, the values for $driver, $user, $database, $server, $port, and $database will be extracted from it.

public string, null $url null

$user public property #

The database username to connect with.

public string $user 'root'

Method Details

init() public method #

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

public void init ( )

updateDsn() public method #

Updates the DSN string based on the config setting values.

public void updateDsn ( )