<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of PHPClass
*
* @author admin
*/
class db{
private $host;
private $name;
private $user;
private $pass;
private $connect;
private $select;
public function __construct($host,$name,$user,$pass){
$this->host=$host;
$this->name=$name;
$this->user=$user;
$this->pass=$pass;
}
public function connect(){
$this->connect=mysql_connect($this->host,$this->user,$this->pass);
if(!$this->connect){
throw new Exception(".:!Errore durante la connessione al database, se l'errore persiste contattare l'admin!:.");
}else{
$this->select();
}
}
private function select(){
$select=mysql_select_db("my_vincy6web",$this->connect);
if(!$select){
exit(".:!Errore durante la selezione!:.");
}
}
}
class guestbook{
private $nome;
private $testo;
private $data;
private $ora;
public $read=array();
public function control($nome,$testo,$data,$ora){
$nome=trim($nome);
$testo=trim($testo);
if(empty($nome) || empty($testo)){
throw new Exception(".:!Compilare tutti i campi, grazie!:.");
return false;
}else{
$nome=htmlentities($nome);
$testo=htmlentities($testo);
$this->nome=$nome;
$this->testo=$testo;
$this->ora=$ora;
$this->data=$data;
return true;
}
}
public function read(){
$query=mysql_query("SELECT * FROM guestbook ORDER BY id DESC");
if(!$query){
throw new Exception(".:!Impossibile leggere i commenti, aggiornare la pagina , se l'errore si ripresenta contattare l'admin!:.");
}
while($all=mysql_fetch_array($query)){
$this->nome=$all['nome'];
$this->testo=$all['testo'];
$this->data=$all['data'];
$this->ora=$all['ora'];
array_push($this->read,array("nome"=>$this->nome,"testo"=>$this->testo,"data"=>$this->data,"ora"=>$this->ora));
}
}
public function write($nome,$testo,$data,$ora){
if($this->control($nome,$testo,$data,$ora)){
$query=mysql_query("INSERT INTO guestbook (nome,testo,data,ora) VALUE ('$nome','$testo','$data','$ora')");
if(!$query){
throw new Exception(".:!Commento non inserito correttamente, riprovare se l'errore persiste contattatare l'admin!:.");
}else{
throw new Exception(".:!Commento inserito correttamente!:.");
}
}
}
}catch(Exception $e) {
echo $e->getMessage();
}
?>