Ok ho fatto un bel pò di prove sulla struttura da te indicata e mi pare veramente una figata.
Data la sua facile comprensione l'ho preso aimè un pò come santo graal.
Per quanto riguarda la gestione delle eccezzioni ho fatto in questo modo :
Class db.php
Codice PHP:
public function connect(){
if($this->isConnected())
return true;//throw new Exception('Connessione già attiva');
try{
$dsn = $this->getDSN();
$this->pdo = new PDO($dsn, $this->username, $this->password);
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->pdo->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
$this->connected = true;
}catch(PDOException $ex){
$this->pdo = null;
$this->connected = false;
//$this->lastError = $ex->getMessage();
$this->GestisciEccezzione();
}
return $this->isConnected();
}
private function GestisciEccezzione($ex){
if($this->conf->get('debug')){
try{
$mail = new PHPMailer(true); //set true exception
$mail->Mailer = $this->conf->get('mail.mailer');
$mail->Host = $this->conf->get('mail.host');
$mail->Port = $this->conf->get('mail.port');
$mail->Username = $this->conf->get('mail.username');
$mail->Password = $this->conf->get('mail.password');
$mail->FromName = "ISDM";
$mail->AddAddress($this->conf->get('mail.dest_err'));
$mail->IsHTML(true);
$mail->Subject = "Error ISDM";
$mail->Body = $ex->__tostring();
$mail->Send();
}catch(phpmailerException $e){
echo "ERRORE MAIL :
";
echo $e->errorMessage();
}
header('location:'.$this->conf->get['application.root'].'login.php?Err= Si e\' verificato un errore interno. Il supporto tecnico e\' stato informato tramite mail.');
}else{
echo "Errore Intercettato :
".$ex->__tostring()."
";
die();
}
}
Pagina test.php
Codice PHP:
<?php
include_once "config/configuration.php";
$conf = new Configuration('config/application.setting.ini');
include_once $conf->get['application.root']."class/PHPMailer_v5.1/class.phpmailer.php";
include_once $conf->get['application.root']."class/db.class.php";
$db = new DB($conf);
$db->connect();
foreach($db->fetchAll("SELECT user FROM utent") as $row){
echo $row['user']."
";
//print_r($row);
}
echo "ciao";
Più che altro non riesco a capire se risulta pratica corretta dichiarare nella pagina di test prima di tutto la classe phpmailer.php
e poi tutte le altre classi, in modo da poter dichiarare al suo interno l'oggetto phpmailer