LogManager.php
<?php
class LogManager{
public function __construct(){
}
public function setLog($msg){
if(!file_exists(LOG_PATH.LOG_FILE_NAME)){
$log= fopen(LOG_PATH.LOG_FILE_NAME, "w") or die ("Worning!: log file non creato.");
fwrite($log, date("Y-m-d H:i:s")."] LogManager\n\n");
}else{
$log= fopen(LOG_PATH.LOG_FILE_NAME, "a");
fwrite($log, date("Y-m-d H:i:s"). " - ".$msg."\n");
fclose($log);
}
}
}
?>
DBManager.php
<?php
require_once('DB.php');
class DBManager{
private $user= "";
private $password= "";
private $host= "";
private $name= "";
public function __construct($user, $password, $host, $name){
$this->user= $user;
$this->password= $password;
$this->host= $host;
$this->name= $name;
}
//*********************** CONNESSIONE ******************************************
public function getConn(){
try{
$db= mysql_connect($this->host, $this->user, $this->password);
mysql_select_db($this->name);
}catch(Exception $e){
$logManager= new LogManager();
$logManager->setLog("Fallita connessione al database - ".$e->getMessage());
}
return $db;
}
public function dropConn($db){
try{
mysql_close($db);
}catch (Exception $e){
$logManager= new LogManager();
$logManager->setLog("Errore di disconnessione dal database - ".$e->getMessage());
}
}
//*********************** QUERY ******************************************
public function runQuery($db, $query){
$data= array();
try{
$dataObj= mysql_query($query, $db);
while($row= mysql_fetch_assoc($dataObj)){
$data[]= $row;
}
}catch (Exception $e){
$logManager= new LogManager();
$logManager->setLog("Errore query: ".$query);
}
return $data;
}
public function runInsert($db, $query){
try{
mysql_query($query, $db);
$lastId=mysql_insert_id();
return $lastId;
}catch (Exception $e){
$logManager= new LogManager();
$logManager->setLog("Errore query: ".$query);
}
}
public function runQueryUpDel($db, $query){
try{
mysql_query($query, $db);
}catch (Exception $e){
$logManager= new LogManager();
$logManager->setLog("Errore query: ".$query);
}
}
//*********************** QUERY ******************************************
}
?>
header.php e visualizza.php sono inutili. la prima contiene un header con un javascript per i pulsanti del menù, la seconda è vuota.