How can I connect to the database (PHP in 3 Layers [Façade / Repository / Bank]) by reading the information from an .ini file and assigning those values to a function inside a class?
Banco.php
class Banco {
var $server;
var $bd;
var $user;
var $password;
var $erro;
var $result;
var $conexao;
function Banco ($user="usuario",$pass="senha",$db="banco",$srv="servidor") {
if(!$this -> SetConexao($srv,$user,$pass)) {
$this -> SetErro("Erro de Conexão - ".mssql_get_last_message($this -> GetConexao()));
mssql_close();
return false;
}
if(!$this -> SetBd($db)) {
$this -> SetErro("Banco não Encontrado - ".mssql_get_last_message($this -> GetConexao()));
mssql_close();
return false;
}
}
.......... mais código .........
}
.INI file
[BANCO]
user = usuario
pass = senha
db = banco
srv = servidor
Reading .INI File
$ini = parse_ini_file('config.ini', true);
$cUser = $ini['BANCO']['user'];
$cPass = $ini['BANCO']['pass'];
$cDb = $ini['BANCO']['db'];
$cSrv = $ini['BANCO']['srv'];
Class .... {
blabla.....
function Banco ($user=$cUser,$pass=$cPass,$db=$cDb,$srv=$cSrv) { <-- Erro ao conectar ao banco
Would anyone have any idea how I could make this kind of connection without having to undo the connection layers in php?