<?php
class DB_Exception extends
Exception {}
class Contact extends DB_Exception{
private $connection;
private $resultset;
public $id = array();
public $name = array();
public $vorname = array();
function __construct() {
include_once("config.php");
$this->connection = mysql_connect($dbserver, $user, $password);
if ($this->connection == false)
{
die(mysql_error());
}
$
db = mysql_select_db("usr_l3s11195_1");
if ($
db == false)
{
die(mysql_error());
}
}
function __destruct() {
mysql_free_result($this->resultset);
mysql_close($this->connection);
}
public function getByName() {
$
query = "SELECT
a.*, k.name as k_name
FROM adressen_data a
LEFT OUTER JOIN adressen_kat k on k.id = a.kategorie_id
WHERE a.name LIKE '%".$this->name[0]."%'
ORDER BY k.id, a.name, a.vorname, a.gesch_firma";
$this->resultset = mysql_query($
query);
if (!$this->resultset) {
throw new DB_Exception(@mysql_error());
}
$this->clearFields();
$this->fillFields();
}
public function getBySurname() {
$
query = "SELECT
a.*, k.name as k_name
FROM adressen_data a
LEFT OUTER JOIN adressen_kat k on k.id = a.kategorie_id
WHERE a.vorname LIKE '%".$this->vorname[0]."%'
ORDER BY k.id, a.name, a.vorname, a.gesch_firma";
$this->resultset = mysql_query($
query);
if (!$this->resultset) {
throw new DB_Exception(@mysql_error());
}
$this->clearFields();
$this->fillFields();
}
public function getById() {
$
query = "SELECT
a.*, k.name as k_name
FROM adressen_data a
LEFT OUTER JOIN adressen_kat k on k.id = a.kategorie_id
WHERE a.id = '".$this->id[0]."'
ORDER BY k.id, a.name, a.vorname, a.gesch_firma";
$this->resultset = mysql_query($
query);
if (!$this->resultset) {
throw new DB_Exception(@mysql_error());
}
$this->clearFields();
$this->fillFields();
}
public function save() {
}
public function edit() {
}
private function fillFields() {
while ($row = mysql_fetch_object($this->resultset)) {
$this->id[] = $row->id;
$this->name[] = $row->name;
$this->vorname[] = $row->vorname;
}
}
private function clearFields() {
unset($this->id);
unset($this->name);
unset($this->vorname);
}
}
?>