Размер файла: 1.29Kb
<?
/**
* Подключения PDO класса для работы с БД
*/
f_import('lib/db.class.php');
# Определение данных
switch ($_SERVER['SERVER_ADDR']) {
case '127.0.0.1':
define('DBHOST', 'localhost');
define('DBPORT', '');
define('DBNAME', 'dumper');
define('DBUSER', 'root');
define('DBPASS', '');
break;
default:
define('DBHOST', $config_mysql['db_server']);
define('DBPORT', '');
define('DBNAME', $config_mysql['db_name']);
define('DBUSER', $config_mysql['db_user']);
define('DBPASS', $config_mysql['db_pass']);
}
class DB {
static $dbh;
public function __construct() {
try {
self :: $dbh = new PDO_('mysql:host=' . DBHOST . ';port=' . DBPORT . ';dbname=' . DBNAME, DBUSER, DBPASS);
self :: $dbh->exec('SET CHARACTER SET utf8');
self :: $dbh->exec('SET NAMES utf8');
} catch (PDOException $e) {
die('Connection failed: ' . $e->getMessage());
}
}
}
$database = new DB();
?>