To make b2db connect to a database, bootstrap it from a file in your application that is included on all requests,
by calling \b2db\Core::initialize($options, $cache)
, where $options
is an array with the information
required to connect to the database.
Some frameworks can do this automatically using service configurations.
Valid $options
elements
<?php
$options = [
'dsn' => '', // a valid DSN connection string
'username' => '',
'password' => '',
'driver' => '', // a valid driver, see the drivers list
'hostname' => '',
'port' => '',
'database' => '',
// optional
'tableprefix' => '', // prefix for all your tables, if used (default '')
'debug' => '', // true / false to turn on or off debug mode (default false)
'caching' => '', // true / false to turn on or off caching (default false)
];
If $options['caching']
is true
(or not defined), or $options['debug']
is false
, you should
pass a cache object that implements interfaces\Cache
as the second parameter.
If you pass a valid DSN configuration string, you don't need to pass any of the other configuration entries, as the DSN usually contains all necessary information to connect to the database.
The valid database drivers are:
mysql
- connects to MySQL and MariaDB databasespgsql
- connects to a PostgreSQL databasemssql
- connects to a Microsoft SQL server database