Er zijn al menig classes voor MySQL, maar het schijnt een goede oefening te zijn!
Dus bij deze! Gaat dit goed zo ?
<?php
error_reporting(E_ALL);
class dbConnection
{
// Basic Propertys
protected $host = 'localhost';
protected $user = 'laurens';
protected $pass = 'landstede110';
protected $db = 'test_db';
// Changeable propertys
protected $link_ID = 0;
protected $select_DB = 0;
protected $do_query = 0;
function __construct()
{
$this->link_ID = mysql_connect($this->host, $this->user, $this->pass);
if (!$this->link_ID)
{
return $this->trigger_db_error(mysql_error());
}
if ($this->link_ID)
{
$this->select_DB = mysql_select_db($this->db);
if (!$this->select_DB)
{
return $this->trigger_db_error(mysql_error());
}
}
}
function do_query($query)
{
$this->do_query = mysql_query($query);
if (!$this->do_query)
{
return $this->trigger_db_error(mysql_error());
}
while($row = mysql_fetch_array($this->do_query))
{
$Data[] = $row;
}
return $Data;
}
function trigger_db_error($error)
{
return sprintf('%s', $error);
}
}
$Connection = new dbConnection();
print_r($Connection->do_query("SELECT * FROM persons"));
?>