Interface
Posted: Tue May 26, 2009 6:31 am
what is the benefits of interface.
i make this interface.
like
so if i remove implements DB.
then no effect on result same functionality work.
then why need make an interface.
can any one help me with thanks
i make this interface.
like
Code: Select all
interface DB
{
public function connect();
public function query($query);
public function fetch_array($result);
}
class MySqlDB implements DB
{
private $link;
public function connect($server='', $username='', $password='', $new_link=true, $client_flags=0)
{
$this->link = mysql_connect($server, $username, $password, $new_link, $client_flags);
}
public function query($query)
{
return mysql_query($query, $this->link);
}
public function fetch_array($result, $array_type = MYSQL_BOTH)
{
return mysql_fetch_array($result, $array_type);
}
}
$db = new MySqlDB;
$db->connect('localhost', 'root', '123');
$db->query('dvdstore');
$result = $db->query("SELECT * FROM actress");
while($row = $db->fetch_assoc($reuslt)) {
echo($row['Name']);
} so if i remove implements DB.
then no effect on result same functionality work.
then why need make an interface.
can any one help me with thanks