Caute,
robim pre jedno OZ stranku. Vytvaram tam tabulky, no a chcem, aby po prihlaseni na tuto stranku sa skontrolovalo, ci ta tabulka existuje a ak nie tak ju vytvori. Zatial to mam takto:
Kód:
<?php
$DB_USER = '';
$DB_PASSWD = '';
$DB_NAME = '';
$SERVER = '';
$connect = '';
class Databaza {
public function __construct() {
$this -> DB_NAME = 'OZ_Pohlad';
$this -> DB_USER = 'Administrator';
$this -> DB_PASSWD = 'T1An0ObpJRWCqoPS';
$this -> SERVER = 'localhost';
$this -> connect = new PDO('mysql:host=' . $this -> SERVER . ";dbname=" . $this -> DB_NAME, $this -> DB_USER, $this -> DB_PASSWD);
$this -> connect -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
public function dbClanky() {
$DB_Clanky = " CREATE TABLE Clanky (
id INTEGER AUTO_INCREMENT PRIMARY KEY,
nadpis VARCHAR(100),
datum VARCHAR(10),
obsah LONGTEXT
)";
try {
$this -> connect -> query($DB_Clanky);
} catch(PDOException $error) {
echo $error -> getMessage();
}
}
public function historia() {
$DB_Historia = " CREATE TABLE Historia (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
historia LONGTEXT
)";
try {
$this -> connect -> query($DB_Historia);
} catch(PDOException $error) {
echo $error -> getMessage();
}
}
public function vitajte() {
$DB_Vitajte = "CREATE TABLE Vitajte (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
vitajte LONGTEXT
)";
try {
$this -> connect -> query($DB_Vitajte);
} catch(PDOException $error) {
echo $error -> getMessage();
}
}
public function spolupraca() {
$DB_Spolupraca = "CREATE TABLE Spolupraca (
id INTEGER AUTO_INCREMENT PRIMARY KEY,
organizacia VARCHAR(200),
od VARCHAR(10)
)";
try {
$this -> connect -> query($DB_Spolupraca);
} catch(PDOException $error) {
echo $error -> getMessage();
}
}
public function kontakty() {
$DB_Kontakty = "CREATE TABLE Kontakty (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
meno VARCHAR(30),
priezvisko VARCHAR(60),
cislo VARCHAR(20),
titul VARCHAR(35)
)";
try {
$this -> connect -> query($DB_Kontakty);
} catch(PDOException $error) {
echo $error -> getMessage();
}
}
}
$vytvor = new Databaza();
$vytvor -> dbClanky();
$vytvor -> historia();
$vytvor -> vitajte();
$vytvor -> spolupraca();
$vytvor -> kontakty();
$connect = null;
Za rady dakujem