Name: Anonymous 2009-08-31 0:32
Learning OO PHP (inb4 *)
I was wondering what /prog/ thought of my database connection class? Oh, and I know that the interface isn't necessary, but it's a habit I picked up from my teacher.
Is it okay? How can I improve on it?
I was wondering what /prog/ thought of my database connection class? Oh, and I know that the interface isn't necessary, but it's a habit I picked up from my teacher.
<?php
interface Database
{
function __construct();
function __destruct();
}
class Connection implements Database
{
private $mysqli;
private $host = "localhost";
private $user = "root";
private $pass = "saucepl0x";
private $name = "content";
public static function __construct()
{
$this->mysqli = new mysqli($this->host, $this->user, $this->pass, $this->name);
if (mysqli_connect_errno())
{
printf ("Connection failed: %s\n", mysqli_connect_error())
}
else
{
return $this->mysqli;
}
}
public static function __destruct()
{
if ($this->mysqli)
{
$this->mysqli->close();
}
}
}
?>Is it okay? How can I improve on it?