I don't know why user, host and password variables are undefined when I try to call the connect() method
$app->get('/get', function () use($app){
$db = new Db_handler;
$db->connect();
}
);
And here is the Db_handler class itself
<?php
class Db_handler{
private $driver;
private $host;
private $port;
private $schema;
private $username;
private $password;
function Db_handler( $config_file = 'connection.ini' ){
if(!$connection_data = parse_ini_file($config_file, true)) throw new exception("No se puedo abrr el fichero de configuracion ".$config_file." .");
$driver = $connection_data["database"]["driver"];
$host = $connection_data["database"]["host"];
$port = $connection_data["database"]["port"];
$schema = $connection_data["database"]["schema"];
$username = $connection_data["database"]["username"];
$password = $connection_data["database"]["password"];
echo $host;
echo $username;
echo $password;
}
function connect(){
$link = mysql_connect($host, $username, $root)
or die('No se pudo conectar: ' . mysql_error());
}
}
?>
The echo of the constructor shows the variables correctly.