acces bd oop

<?php
class Database{

protected $result, $num_rows,$db_name,$conn;

public function __construct($server, $username, $pass, $db_name){

$this->db_name = $db_name;

$this->conn = @new mysqli($server,$username,$pass,$db_name);
if(!$this->conn->connect_error)
{
echo “avem conexiune la baza de date (constructor)”.$this->db_name.”<br>”;
}
else
{
echo “Eroare la conectare “.$this->conn->connect_error;
}

}

public function disconnect(){
$this->conn->close();
}

public function query($sql)
{

$this->result = $this->conn->query($sql);
$this->num_rows = $this->result->num_rows;
}
public function rows()
{
$rows = array();
for ($i=0; $i<$this->num_rows; $i++) {
# code…
$rows[$i] = $this->result->fetch_assoc();
}
return $rows;
}

public function get_conn(){
return $this->conn;
}

public function get_num_rows(){
return $this->num_rows;
}

}
?>

<?php
$db_name = “scoala”;
$db = new Database(“localhost”,”root”,””,$db_name);
$conexiune = $db->get_conn();
if(!$conexiune->connect_error)
{
// echo “avem conexiune la baza de date “.$db_name.” din instanta db <br>”;

$db->query(“select * from personal”);
// echo “Interogarea a returnat un numar de “.$db->get_num_rows().” randuri <br>”;

if($db->get_num_rows()>0)
{
foreach ($db->rows() as $row) {
# code…
echo “Nume: “.$row[“nume”]. ” varsta:”.$row[“varsta”].”<br>”;
}
}
$db->disconnect();
}
else
{
echo “Avem probleme cu conectarea la “.$db_name;
}
?>