1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| //includes/databasemanagement.php
define("FILE_NAME","sql/config.ini");
class DatabaseManager{
var $database_name;
var $fn;
var $dsn;
function DatabaseManager(){
$database_name = "";
$dsn = "";
$fn = FILE_NAME;
}
function readConfigFile(){
if($fd=fopen($fn,"r")){
$config = parse_ini_file(FILE_NAME);
if(!isset($config["db_name"]) ||
!isset($config["db_host_dsn"])){
fclose($fd);
header("Location: config.php?error=config_not_formated");
exit;
}
$this->database_name = $config["db_name"];
$this->dsn = $config["db_host_dsn"];
}else{
header("Location: config.php?error=config_not_found");
exit;
}
}
function writeConfigFile(){
if($fd=fopen($fn,"w+")){
$dbnconf = 'db_name = '.$this->database_name.'\n';
$dsnconf = 'db_host_dsn = '.$this->dsn.'\n';
if(!fwrite($fd,$dbnconf)){
fclose($fd);
header("Location: config.php?error=config_not_writable&cause=1");
exit;
}
if(!fwrite($fd,$dbnconf)){
fclose($fd);
header("Location: config.php?error=config_not_writable&cause=2");
exit;
}
}else{
header("Location: config.php?error=config_not_writable&cause=3");
exit;
}
}
} |