DbConfig

Type
Class
Namespace
craft\config
Inherits
craft\config\DbConfig » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.0

DB config class

View source

Public Properties

PropertyDescription
$attributesarray – An array of key => value pairs of PDO attributes to pass into the PDO constructor.
$charsetstring – The charset to use when creating tables.
$databasestring – The name of the database to select.
$driverstring – The database driver to use.
$dsnstring – If you want to manually specify your PDO DSN connection string you can do so here.
$passwordstring – The database password to connect with.
$portinteger – The database server port.
$schemastring – The database schema to use (PostgreSQL only).
$serverstring – The database server name or IP address.
$tablePrefixstring – 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.
$unixSocketstring, null – MySQL only.
$urlstring, null – The database connection URL, if one was provided by your hosting environment.
$userstring – The database username to connect with.

$attributes

Type
array

An array of key => value pairs of PDO attributes to pass into the PDO constructor.

For example, when using the MySQL PDO driver (http://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',
],

View source

Signature

public array $attributes = []

$charset

Type
string

The charset to use when creating tables.

View source

Signature

public string $charset = 'utf8'

$database

Type
string

The name of the database to select.

View source

Signature

public string $database = ''

$driver

Type
string

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

View source

Signature

public string $driver = self::DRIVER_MYSQL

$dsn

Type
string

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

View source

Signature

public string $dsn = null

$password

Type
string

The database password to connect with.

View source

Signature

public string $password = ''

$port

Type
integer

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

View source

Signature

public integer $port = null

$schema

Type
string

The database schema to use (PostgreSQL only).

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

View source

Signature

public string $schema = 'public'

$server

Type
string

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

View source

Signature

public string $server = 'localhost'

$tablePrefix

Type
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. This can be no more than 5 characters, and must be all lowercase.

View source

Signature

public string $tablePrefix = ''

$unixSocket

Type
string, null

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.

View source

Signature

public string, null $unixSocket = null

$url

Type
string, null

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.

View source

Signature

public string, null $url = null

$user

Type
string

The database username to connect with.

View source

Signature

public string $user = 'root'

Public Methods

MethodDescription
__call()Calls the named method which is not a class method.
__construct()Constructor.
__get()Returns the value of an object property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets value of an object property.
__unset()Sets an object property to null.
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
className()Returns the fully qualified name of this class.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined.
init()Initializes the object.
updateDsn()Updates the DSN string based on the config setting values.

init()

Initializes the object.

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

View source

Signature

public void init ( )

updateDsn()

Updates the DSN string based on the config setting values.

View source

Signature

public void updateDsn ( )

Constants

ConstantDescription
DRIVER_MYSQL
DRIVER_PGSQL