setup/index.php
author Markus Bröker<broeker.markus@googlemail.com>
Sat, 19 Dec 2015 02:07:59 +0100
changeset 30 5751ca5a55c0
parent 19 95ee596c03c5
child 39 8b4f9c6136f4
permissions -rw-r--r--
Richtiges Persistence Framework mit echten Gettern und Settern + Creator

<?php

header('Content-Type: text/plain');

$cfg = array(
    'dsn' => 'mysql:host=localhost;',
    'config' => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'),
    'username' => 'root',
    'password' => '',
);

require_once '../config/config.php';

use bfw\database\Database;

$db = Database::getInstance($cfg);

$dropSQLStatements = array(
    "DROP USER 'bfw'@'localhost'",
    "DROP DATABASE IF EXISTS bfw;",
);

$createSQLStatements = array(
    "CREATE DATABASE bfw CHARACTER SET utf8 COLLATE utf8_unicode_ci;",
    "CREATE USER 'bfw'@'localhost' IDENTIFIED BY 'bfw';",
    "GRANT ALL PRIVILEGES ON bfw.* TO 'bfw'@'localhost' WITH GRANT OPTION;",
);

foreach ($dropSQLStatements as $statement) {
    $status = $db->execute($statement);
    echo sprintf("%s\n", $statement);
}

foreach ($createSQLStatements as $statement) {
    $status = $db->execute($statement);
    echo sprintf("%s\n", $statement);
}

$handle = fopen(BFW_PATH . '/sql/init.sql', 'r');

$sql = "USE bfw;\n\n";
while (!feof($handle)) {
    $sql .= fgets($handle);
}

fclose($handle);

if ($db->execute($sql) == 0) {
    echo sprintf("%s", $sql);

    header('Location: /');
}