DbConfig
- Type
- Class
- Namespace
- craft\config
- Inherits
- craft\config\DbConfig » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Since
- 3.0.0
DB config class
Public Properties
Property | Description |
---|---|
attributes | array – An array of key => value pairs of PDO attributes to pass into the PDO constructor. |
charset | string – The charset to use when creating tables. |
collation | string, null – The collation to use when creating tables. |
database | string, null – The name of the database to select. |
driver | string, null – The database driver to use. |
dsn | string, null – The Data Source Name (“DSN”) that tells Craft how to connect to the database. |
password | string – The database password to connect with. |
port | integer, null – The database server port. |
schema | string – The schema that Postgres is configured to use by default (PostgreSQL only). |
server | string, null – The database server name or IP address. |
setSchemaOnConnect | boolean – Whether the schema should be explicitly used for database queries (PostgreSQL only). |
tablePrefix | string – If you’re sharing Craft installs in a single database (MySQL) or a single database and using a shared schema (PostgreSQL), you can set a table prefix here to avoid per-install table naming conflicts. |
unixSocket | string, null – MySQL only. |
url | string, null – The database connection URL, if one was provided by your hosting environment. |
useUnbufferedConnections | boolean – Whether batched queries should be executed on a separate, unbuffered database connection. |
user | string – The database username to connect with. |
attributes
- Type
- array
- Default value
[]
An array of key => value pairs of PDO attributes to pass into the PDO constructor.
charset
- Type
- string
- Default value
'utf8'
The charset to use when creating tables.
collation
The collation to use when creating tables.
database
The name of the database to select.
driver
The database driver to use. Either mysql
for MySQL or pgsql
for PostgreSQL.
dsn
The Data Source Name (“DSN”) that tells Craft how to connect to the database.
password
- Type
- string
- Default value
''
The database password to connect with.
port
The database server port. Defaults to 3306 for MySQL and 5432 for PostgreSQL.
schema
- Type
- string
- Default value
'public'
The schema that Postgres is configured to use by default (PostgreSQL only).
See also https://www.postgresql.org/docs/8.2/static/ddl-schemas.html
server
The database server name or IP address. Usually localhost
or 127.0.0.1
.
setSchemaOnConnect
- Type
- boolean
- Default value
false
- Since
- 3.7.27
Whether the schema should be explicitly used for database queries (PostgreSQL only).
tablePrefix
- Type
- string
- Default value
''
If you’re sharing Craft installs in a single database (MySQL) or a single database and using a shared schema (PostgreSQL), you can set a table prefix here to avoid per-install table naming conflicts. This can be no more than 5 characters, and must be all lowercase.
unixSocket
MySQL only. If this is set, 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.
url
The database connection URL, if one was provided by your hosting environment.
useUnbufferedConnections
- Type
- boolean
- Default value
false
- Since
- 3.7.0
Whether batched queries should be executed on a separate, unbuffered database connection.
user
- Type
- string
- Default value
'root'
The database username to connect with.
Public Methods
Method | Description |
---|---|
__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.
Throws
updateDsn()
DEPRECATED
Deprecated in 3.4.0.
Updates the DSN string based on the config setting values.
Throws
- yii\base\InvalidConfigException
if driver isn’t set tomysql
orpgsql
.
Constants
Constant | Description |
---|---|
DRIVER_MYSQL | |
DRIVER_PGSQL |