2021-12-28 23:49:45 +01:00
|
|
|
<?php
|
2021-12-29 23:09:05 +01:00
|
|
|
try {
|
|
|
|
// Verbindung zur Datenbank herstellen
|
2021-12-30 12:58:03 +01:00
|
|
|
$pdo = new PDO('mysql:host=localhost;dbname=linkdb', 'linkdb', 'linkdb');
|
2021-12-29 23:09:05 +01:00
|
|
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
2021-12-28 23:49:45 +01:00
|
|
|
|
2021-12-29 23:09:05 +01:00
|
|
|
// Tabelle link erstellen, falls nicht vorhanden
|
|
|
|
$sql = 'CREATE TABLE IF NOT EXISTS link (
|
|
|
|
link_id BIGINT(18) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
link_url VARCHAR(30) NOT NULL,
|
|
|
|
link_name VARCHAR(30),
|
|
|
|
reg_date TIMESTAMP
|
|
|
|
)';
|
|
|
|
|
|
|
|
$pdo->exec($sql); // use exec() because no results are returned
|
|
|
|
}
|
|
|
|
catch(PDOException $e)
|
|
|
|
{
|
|
|
|
echo $sql . "<br>" . $e->getMessage();
|
|
|
|
}
|
|
|
|
|
2022-01-08 22:43:50 +01:00
|
|
|
|
|
|
|
// Versuch der Objektorientierung
|
|
|
|
|
|
|
|
class Link{
|
|
|
|
public $name;
|
|
|
|
public $url;
|
|
|
|
|
|
|
|
public function __construct($newName, $newUrl){
|
|
|
|
$this->name = $newName;
|
|
|
|
$this->url = $newUrl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$link1=new Link("therealblue.de", "https://therealblue.de");
|
|
|
|
|
|
|
|
echo '<a href="'.$link1->url.'" target="_blank">'.$link1->name.'</a><br>';
|
|
|
|
|
|
|
|
/* Alt vor Obejktorientierung
|
|
|
|
|
2021-12-29 23:09:05 +01:00
|
|
|
$url = 'https://therealblue.de';
|
|
|
|
$name = 'therealblue.de';
|
|
|
|
|
|
|
|
$statement = $pdo->prepare('INSERT INTO link(link_url, link_name) VALUES (:link_url, :link_name)');
|
|
|
|
$statement->execute([
|
|
|
|
':link_url' => $url,
|
|
|
|
':link_name' => $name
|
|
|
|
]);
|
2021-12-28 23:49:45 +01:00
|
|
|
|
|
|
|
$sql = "SELECT * FROM link";
|
|
|
|
foreach ($pdo->query($sql) as $row) {
|
|
|
|
echo '<a href="'.$row['link_url'].'" target="_blank">'.$row['link_name'].'</a><br>';
|
|
|
|
}
|
2022-01-08 22:43:50 +01:00
|
|
|
*/
|
2021-12-28 23:49:45 +01:00
|
|
|
|
|
|
|
?>
|