Skip to content

Instantly share code, notes, and snippets.

@noxifoxi
Created May 8, 2012 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noxifoxi/2638411 to your computer and use it in GitHub Desktop.
Save noxifoxi/2638411 to your computer and use it in GitHub Desktop.
blub
<?php
define('CFG', 1);
define('CFG_DEBUG', 1);
// Database Config
define('CFG_DB_TYPE', 'MySQL');
define('CFG_DB_USER', 'root');
define('CFG_DB_PASSWORD', '');
define('CFG_DB_DATABASE', 'silexboard');
define('CFG_DB_PREFIX', '');
define('CFG_DB_HOST', 'localhost');
define('CFG_DB_PORT', '');
define('CFG_DB_SOCKET', '');
define('CFG_CACHE_DIR', DIR_ROOT.'lib/cache/');
/* --- Currently not needed stuff --- */
// Cache info
define('CFG_CACHE_TYPE', 'File');
// URL info
define('CFG_BASE_URL', 'http://localhost/SilexBoard/');
?>
<?php
/**
* @author SilexBB
* @copyright 2011 - 2012 Silex Bulletin Board
* @license GPL version 3 or higher <http://www.gnu.org/licenses/gpl-3.0.html>
*/
/**
* Returns a new PDO instance based on the settings of the configuration
* @return PDO
*/
class Database {
public static function GetDatabase() {
switch(strtolower(CFG_DB_TYPE)) {
case 'mysql':
if(!empty(CFG_DB_PORT))
return new PDO('mysql:host='.CFG_DB_HOST.';port='.CFG_DB_PORT.';dbname='.CFG_DB_DATABASE, CFG_DB_USER, CFG_DB_PASSWORD);
if(!empty(CFG_DB_SOCKET))
return new PDO('mysql:unix_socket='.CFG_DB_SOCKET.';dbname='.CFG_DB_DATABASE, CFG_DB_USER, CFG_DB_PASSWORD);
return new PDO('mysql:host='.CFG_DB_HOST.';dbname='.CFG_DB_DATABASE, CFG_DB_USER, CFG_DB_PASSWORD);
case 'sqlite':
return new PDO('sqlite:'.CFG_DB_DATABASE.'.db');
case 'pgsql':
if(!empty(CFG_DB_PORT))
return new PDO('pgsql:host='.CFG_DB_HOST.';port='.CFG_DB_PORT.';dbname='.CFG_DB_DATABASE.';user='.CFG_DB_USER.';password='.CFG_DB_PASSWORD);
if(!empty(CFG_DB_SOCKET))
return new PDO('pgsql:unix_socket='.CFG_DB_SOCKET.';dbname='.CFG_DB_DATABASE.';user='.CFG_DB_USER.';password='.CFG_DB_PASSWORD);
return new PDO('pgsql:host='.CFG_DB_HOST.';port=5432;dbname='.CFG_DB_DATABASE.';user='.CFG_DB_USER.';password='.CFG_DB_PASSWORD);
default:
throw new DatabaseException('The database type "'.CFG_DB_TYPE.'" is currently not supported');
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment