wootook-reloaded/includes/application/code/community/Legacies/Database.php
Gregory PLANCHAT d7619777af Initial commit
2011-06-07 09:23:48 +02:00

32 lines
No EOL
1,018 B
PHP

<?php
class Legacies_Database
extends PDO
{
protected static $_singleton = null;
protected static $_prefix = null;
public static function getSingleton()
{
if (self::$_singleton === null) {
$config = include ROOT_PATH . 'config.php';
$hostname = $config['global']['database']['options']['hostname'];
$username = $config['global']['database']['options']['username'];
$password = $config['global']['database']['options']['password'];
$database = $config['global']['database']['options']['database'];
self::$_singleton = new self("mysql:dbname={$database};host={$hostname}", $username, $password);
}
return self::$_singleton;
}
public function getTable($name)
{
if (self::$_prefix === null) {
$config = include ROOT_PATH . 'config.php';
self::$_prefix = $config['global']['database']['table_prefix'];
}
return self::$_prefix . $name;
}
}