Overview of configuration options for the Nette Database.
Configure a single database connection:
database: # DSN, only mandatory key dsn: "sqlite2:%appDir%/Model/demo.db" user: ... password: ...
It creates services of type
Nette\Database\Connection and also
Nette\Database\Context for the Database Explorer layer. The database connection is usually passed by
autowiring, if this is not possible, use the service names
database: # shows database panel in Tracy Bar? debugger: ... # (bool) defaults to true # shows query EXPLAIN in Tracy Bar? explain: ... # (bool) defaults to true # to enable autowiring for this connection? autowired: ... # (bool) defaults to true for first connection # table conventions: discovered, static, or class name conventions: discovered # (string) defaults to 'discovered' options: # to connect to the database only when needed? lazy: ... # (bool) defaults to false # PHP database driver class driverClass: # (string) # you can list the options found in the PDO driver documentation PDO::MYSQL_ATTR_COMPRESS: true
In the configuration we can define more database connections by dividing them into named sections:
database: main: dsn: 'mysql:host=127.0.0.1;dbname=test' user: root password: password another: dsn: 'sqlite2::memory:'
Each defined connection creates services that includes section name in their name, ie
@database.main.context and further
Autowiring is enabled only for services from the first section. This can be changed with
autowired: false or
autowired: true. Non-autowired services are passed by name:
services: - UserFacade(@database.another.connection)