Skip to content

Instantly share code, notes, and snippets.

@Fohlen
Created April 2, 2015 10:30
Show Gist options
  • Save Fohlen/ecb8eb625df582cbaa08 to your computer and use it in GitHub Desktop.
Save Fohlen/ecb8eb625df582cbaa08 to your computer and use it in GitHub Desktop.
Global database object with configuration in F3
<?php
// Load configuration
$f3->config('config.ini');
// Prepare the database
$dbConfig = $f3->get('database');
if (!isset($dbConfig['port']))
$dbConfig['port'] = 3306;
$f3->set('DB', new DB\SQL(
'mysql:host='.$dbConfig['host'].';port='.$dbConfig['port'].';dbname='.$dbConfig['database'],
$dbConfig['user'],
$dbConfig['password']
));
/*
Corresponding config.ini
[database]
host=localhost
database=cubelounge
user=cubelounge
password=
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment