This repository was archived by the owner on Jun 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_setup.php
More file actions
46 lines (37 loc) · 1.29 KB
/
db_setup.php
File metadata and controls
46 lines (37 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
//get the DB login data
require_once 'config.php';
//check if INSTALL flag == 1
if(INSTALL!=1){
$errorTitle='Konnte DB nicht initialisieren';
$error='Die Konstante INSTALL ist nicht richtig gesetzt, überprüfe die config.php.';
include './templates/error.php';
die;
}
function processFile($path){
$sqlScript = file_get_contents($path);
//strip unnecessary things
$sqlScript = preg_replace ("%/\*(.*)\*/%Us", '', $sqlScript);
$sqlScript = preg_replace ("%^--(.*)\n%mU", '', $sqlScript);
$sqlScript = preg_replace ("%^$\n%mU", '', $sqlScript);
$sqlScript = preg_replace ("/ordermgmt/", DB_DATABASE, $sqlScript);
//open connection
include 'db_connect.php';
//escaping
mysql_real_escape_string($sqlScript);
$queries = explode(";", $sqlScript);
$success = true;
foreach ($queries as $query){
if ($query != '' && $query != ' '){
$success=$success&&mysql_query($query);
}
}
if($success){
echo "Erfolg \n";
}
}
echo "Erstelle Datenbankschema \n";
processFile('./installfiles/db_create_script.sql');
echo "Fülle Datenbank mit Daten\n";
processFile('./installfiles/db_insert_script.sql');
echo "Datenbank Erstellung abgeschlossen, Sie können das Flag INSTALL in der config.php auf 0 setzen. \n";