|
1 <?php |
|
2 |
|
3 header('Content-Type: text/plain'); |
|
4 |
|
5 $cfg = array( |
|
6 'dsn' => 'mysql:host=localhost;', |
|
7 'config' => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'), |
|
8 'username' => 'root', |
|
9 'password' => '', |
|
10 ); |
|
11 |
|
12 require_once '../config/config.php'; |
|
13 |
|
14 use bfw\database\Database; |
|
15 |
|
16 $db = Database::getInstance($cfg); |
|
17 |
|
18 $dropSQLStatements = array( |
|
19 "DROP USER 'bfw'@'localhost'", |
|
20 "DROP DATABASE IF EXISTS bfw;", |
|
21 ); |
|
22 |
|
23 $createSQLStatements = array( |
|
24 "CREATE DATABASE bfw CHARACTER SET utf8 COLLATE utf8_unicode_ci;", |
|
25 "CREATE USER 'bfw'@'localhost' IDENTIFIED BY 'bfw';", |
|
26 "GRANT ALL PRIVILEGES ON bfw.* TO 'bfw'@'localhost' WITH GRANT OPTION;", |
|
27 ); |
|
28 |
|
29 foreach ($dropSQLStatements as $statement) { |
|
30 $status = $db->execute($statement); |
|
31 echo sprintf("%s\n", $statement); |
|
32 } |
|
33 |
|
34 foreach ($createSQLStatements as $statement) { |
|
35 $status = $db->execute($statement); |
|
36 echo sprintf("%s\n", $statement); |
|
37 } |
|
38 |
|
39 $handle = fopen(BFW_PATH . '/sql/init.sql', 'r'); |
|
40 |
|
41 $sql = "USE bfw;\n\n"; |
|
42 while (!feof($handle)) { |
|
43 $sql .= fgets($handle); |
|
44 } |
|
45 |
|
46 fclose($handle); |
|
47 |
|
48 if ($db->execute($sql) == 0) { |
|
49 echo sprintf("%s", $sql); |
|
50 |
|
51 header('Location: /'); |
|
52 } |