diff --git a/link.php b/link.php index 8644b0b..a43d179 100644 --- a/link.php +++ b/link.php @@ -1,82 +1,17 @@ name = $newName; - $this->url = $newUrl; - } -} +$db = new dbLinkHAndler(); -class dbLinkHandler -{ - private $pdo; +$link = $db->getLink(filter_var($_GET["url"], FILTER_SANITIZE_STRING)); +?> - public function __construct() - { - try - { - // Verbindung zur Datenbank herstellen - $this->pdo = new PDO('mysql:host=localhost;dbname=linkvz', 'linkvz', 'linkvz'); - $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - - // Tabelle link erstellen, falls nicht vorhanden - - $sql = 'CREATE TABLE IF NOT EXISTS link ( - link_url VARCHAR(50) NOT NULL PRIMARY KEY, - link_name VARCHAR(100), - reg_date TIMESTAMP - )'; - - $this->pdo->exec($sql); // use exec() because no results are returned - } - catch(PDOException $e) - { - echo $sql . "
" . $e->getMessage(); - } - } - - public function saveLink($link) - { - try - { - $statement = $this->pdo->prepare('INSERT INTO link(link_url, link_name) VALUES (:link_url, :link_name)'); - $statement->execute - ([ - ':link_url' => $link->url, - ':link_name' => $link->name - ]); - } - catch(PDOException $e) - { - if ($e->errorInfo[1] == 1062) - { - echo 'haaaaaa

'; - } - else - { - echo $e->getMessage(); - } - } - } - - public function getListReverse() - { - // Mit verschachtelten Arrays optimieren!! Array schlüssel id enthält array mit schlüssel link_id, link_name, etc (repräsentiert datensatz) - $list = array(); - $sql = "SELECT * FROM link ORDER BY link_name DESC"; - - return $this->pdo->query($sql); - } - - public function getList() - { - //$sql = "SELECT * FROM link"; - $statement = $this->pdo->prepare("SELECT * FROM link"); - $statement->execute(); - //return $this->pdo->query($sql); - return $statement->fetch; - } -} -?> \ No newline at end of file + + + + +

Name: name; ?>

+

URL: url; ?>

+

Hinzugefügt: reg_date; ?>

+ + \ No newline at end of file diff --git a/link_lib.php b/link_lib.php new file mode 100644 index 0000000..b0e9fe6 --- /dev/null +++ b/link_lib.php @@ -0,0 +1,95 @@ +name = $newName; + $this->url = $newUrl; + } +} + +class dbLinkHandler +{ + private $pdo; + + public function __construct() + { + try + { + // Verbindung zur Datenbank herstellen + $this->pdo = new PDO('mysql:host=localhost;dbname=linkvz', 'linkvz', 'linkvz'); + $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + // Tabelle link erstellen, falls nicht vorhanden + + $sql = 'CREATE TABLE IF NOT EXISTS link ( + link_url VARCHAR(100) NOT NULL PRIMARY KEY, + link_name VARCHAR(50), + reg_date TIMESTAMP + )'; + + $this->pdo->exec($sql); // use exec() because no results are returned + } + catch(PDOException $e) + { + echo $sql . "
" . $e->getMessage(); + } + } + + public function saveLink($link) + { + try + { + $statement = $this->pdo->prepare('INSERT INTO link(link_url, link_name) VALUES (:link_url, :link_name)'); + $statement->execute + ([ + ':link_url' => $link->url, + ':link_name' => $link->name + ]); + } + catch(PDOException $e) + { + if ($e->errorInfo[1] == 1062) + { + echo "haaaaaa!
"; + } + else + { + echo $e->getMessage(); + } + } + } + + public function getListReverse() + { + $statement = $this->pdo->prepare("SELECT * FROM link ORDER BY reg_date DESC"); + $statement->execute(); + + return $statement; + } + + public function getList() + { + $statement = $this->pdo->prepare("SELECT * FROM link"); + $statement->execute(); + + return $statement; + } + + public function getLink($url) + { + $statement = $this->pdo->prepare("SELECT * FROM link WHERE link_url = ?"); + $statement->execute(array($url)); + + $fetch = $statement->fetch(); + + $link = new link($fetch[1], $fetch[0]); + $link->reg_date = $fetch[2]; + + return $link; + } +} +?> \ No newline at end of file