]>
Commit | Line | Data |
---|---|---|
78069032 VP |
1 | <?php |
2 | ||
54b9603c BM |
3 | /** For handling installation BEFORE any backend and user is configured */ |
4 | ||
c06c1713 | 5 | require_once "../inc/common.php"; |
78069032 | 6 | |
f0106ef0 VP |
7 | /* only let this happen pre-config */ |
8 | if (file_exists("../config/config.php")) | |
9680dd58 | 9 | die(json_encode(["error" => "Configuration file exists."])); |
78069032 | 10 | |
055ded3a | 11 | if (!isset($_POST) || empty($_POST)) |
9680dd58 | 12 | die(json_encode(["error" => "Incorrect parameters"])); |
78069032 | 13 | |
eddacbaa | 14 | if ($_POST['method'] == "sql") |
78069032 | 15 | { |
6f2b5b4b | 16 | try { |
eddacbaa | 17 | $conn = mysqli_connect($_POST['host'], $_POST['user'], $_POST['password'], $_POST['database']); |
6f2b5b4b BM |
18 | } catch(Exception $e) |
19 | { | |
20 | } | |
21 | // check connection | |
22 | if (mysqli_connect_errno()) | |
23 | die(json_encode(["error" => "Failed to connect to MySQL: " . mysqli_connect_error()])); | |
24 | ||
25 | $sql = "SHOW TABLES LIKE '".$conn->real_escape_string($_POST['table_prefix'])."%'"; // SQL query to check if table exists | |
26 | $result = $conn->query($sql); | |
27 | if ($result->num_rows > 0) | |
28 | die(json_encode(["warn" => "Database already has data"])); | |
29 | ||
30 | // close connection | |
31 | mysqli_close($conn); | |
32 | die(json_encode(["success" => "SQL Connection successful"])); | |
78069032 | 33 | |
54b9603c | 34 | } |