Repository navigation
Expand file tree
/
Copy pathcheckConn.php
More file actions
57 lines (45 loc) · 1.59 KB
/
Copy pathcheckConn.php
File metadata and controls
57 lines (45 loc) · 1.59 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
47
48
49
50
51
52
53
54
55
56
57
<?php
require_once('config.php');
session_start();
class CheckConn
{
function checkConnection($db, $usr, $pwd)
{
return conn($db, $usr, $pwd);
}
}
if (class_exists('CheckConn')) {
if (isset($_POST['dbName'])) {
$db = $_POST['dbName'];
$user = $_POST['dbUser'];
$password = $_POST['dbPassword'];
$checkCon = new CheckConn();
$conn = $checkCon->checkConnection($db, $user, $password);
$errMessage = '';
$arr = [];
if ($conn === false) {
$errMessage = '<div class="alert alert-dismissible fade show alert-danger" role="alert" data-color="danger">
<strong>Uh oh!</strong> Could not connect to the database!
<button type="button" class="close" data-dismiss="alert">×</button>
</div>';
$arr['alert'] = $errMessage;
} else {
$errMessage = '<div class="alert alert-dismissible fade show alert-success" role="alert" data-color="success">
<strong>Woo hoo!</strong> Connected Succeffuly!
<button type="button" class="close" data-dismiss="alert">×</button>
</div>';
$stmt = $conn->prepare("
select TABLE_NAME, ENGINE from information_schema.TABLES where TABLE_SCHEMA='$db'
");
$stmt->execute();
$res = $stmt->fetchAll();
$_SESSION['login'] = true;
$_SESSION['dbName'] = $db;
$_SESSION['dbUser'] = $user;
$_SESSION['dbPassword'] = $password;
$arr['alert'] = $errMessage;
$arr['tablesInfo'] = $res;
}
echo json_encode($arr);
}
}