Skip to content

Latest commit

 

History

History
42 lines (34 loc) · 1.49 KB

configuration.md

File metadata and controls

42 lines (34 loc) · 1.49 KB

Back to Contents

Configuration

Initialization

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.

DSN

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.

Valid database drivers

The valid database drivers are:

  • mysql - connects to MySQL and MariaDB databases
  • pgsql - connects to a PostgreSQL database
  • mssql - connects to a Microsoft SQL server database