-
Notifications
You must be signed in to change notification settings - Fork 1
/
connect_db.php
34 lines (27 loc) · 1.06 KB
/
connect_db.php
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
<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if (isset($_SESSION['connected'])) {
/* loading json */
$conf = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT']."/conf/appli/conf-appli.json"), true);
$json = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'].$conf['DB']['DB_CONF_PATH']),true);
/* Connexion à une base MySQL avec l'invocation de pilote */
$dsn = 'mysql:dbname='.$json["hdm-core-database"]["database"].';host='.$json["hdm-core-database"]['host'].':'.$json["hdm-core-database"]['port'];
$user = $json["hdm-core-database"]['user'];
$password = $json["hdm-core-database"]['password'];
$conn = NULL;
try {
$conn = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
?>
<div class="alert alert-danger mb-0 p-2" role="alert">
<?php echo 'Connexion échouée : ' . $e->getMessage() . ' | You should consider running the create db script : '; ?>
<a href="/admin/create_db.php">Run the create db script</a>
</div>
<?php
}
} else {
include $_SERVER['DOCUMENT_ROOT'].'/login.php';
}
?>