Ciao a tutti,
Sono consapevole che è pieno zeppo il web di classi già fatte in php per gestire mysql...
Solo che mi sono avvicinato alle classi da pochissimo tempo per questo motivo vorrei un vostro parere circa eventuali miglioramenti da fare...diciamo alla base della classe... per ora c'è poco, magari qualche consiglio non so
grazieeeeee
codice:
class MysqlException extends Exception {};
class MysqlConnection extends MysqlException {};
class DatabaseError extends MysqlException {};
class Mysql{
private $conn, $host, $user, $password, $database;
public function __construct($host, $user, $password, $database='', $connect=true){
$this->host = $host;
$this->user = $user;
$this->password = $password;
$this->database = $database;
if ($connect) $this->connect();
}
public function __destruct(){
$this->close();
}
public function connect(){
$this->conn = mysql_connect($this->host, $this->user, $this->password);
if (!$this->conn)
throw new MysqlConnection("Impossibile connettersi al database");
else
$this->set_database($this->database);
}
public function close(){
if ($this->conn){
if (!mysql_close($this-conn)) throw new MysqlConnection("Impossibile chiudere la connessione al database");
}
}
public function set_database($database){
if (trim($database) && $this->conn){
if (!mysql_select_db($database, $this->conn)) throw new DatabaseError("Impossibile selezionare il database");
}
}
}