Proszę o ocenę i krytykę mojej pierwszej klasy:
<?php
class mySQL
{
private $connection;
private $selectedDb;
private $result;
private $isConnected;
function __contruct()
{
$this->connection = false;
$this->selectedDb = false;
}
final function connect($host, $user, $password, $db_name, $const = false)
{
if ($const)
$this->connection = @mysql_pconnect($host, $user, $password);
else
$this->connection = @mysql_connect($host, $user, $password);
if ($this->connection)
{
$this->isConnected = true;
if ($this->selectDb($db_name))
$this->selectedDb = true;
return true;
} else
$this->printError();
return false;
}
final private function selectDb($name)
{
if ($this->isConnected)
if (@mysql_select_db($name))
return true;
else
$this->printError();
return false;
}
final function query($sql)
{
if ($this->selectedDb)
{
$this->result = mysql_query($sql);
if ($this->result)
return true;
else
return false;
}
}
final function fetchAssoc($sql = '')
{
if ($this->selectedDb)
{
if (!$this->result)
$this->query($sql);
$rows = array();
while ($row = mysql_fetch_assoc($this->result))
$rows[] = $row;
return $rows;
}
}
final function getRow($sql = '')
{
if ($this->selectedDb)
{
if (!$this->result)
$this->query($sql);
return mysql_result($this->result, 0, 0);
}
}
final function selectNumRows($sql = '')
{
if ($this->selectedDb)
{
if (!$this->result)
$this->query($sql);
return mysql_num_rows($this->result);
}
}
final function close()
{
if ($this->selectedDb)
if (mysql_close())
return true;
return false;
}
final function insert()
{
if ($this->selectedDb)
return mysql_insert_id();
return 0;
}
final private function printError($exit = false)
{
echo "<div style=\"font-family:Verdana; font-size:11px; text-align:center; font-weight: bold;\">Nie mozna ustanowic polaczenia z baza danych MySQL<br />".mysql_errno()." : ".mysql_error()."</div>";
if ($exit)
exit();
}
}
$sql = new mySQL;
$sql->connect('localhost', 'root', 'pass', 'base');
$sql->query("ZAPYTANIE");
$sql->close();
?>