create table and store data
parent
71c3895e11
commit
58e9a25332
28
index.php
28
index.php
|
@ -1,6 +1,32 @@
|
|||
<?php
|
||||
|
||||
try {
|
||||
// Verbindung zur Datenbank herstellen
|
||||
$pdo = new PDO('mysql:host=localhost;dbname=links', 'linksdb', 'linksdb');
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
$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
|
||||
]);
|
||||
|
||||
$sql = "SELECT * FROM link";
|
||||
foreach ($pdo->query($sql) as $row) {
|
||||
|
|
Loading…
Reference in New Issue