Skip to content

Commit 40bfc77

Browse files
committed
packing the database connection into json constant file
1 parent a030cfe commit 40bfc77

File tree

6 files changed

+71
-53
lines changed

6 files changed

+71
-53
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
*.ftpconfig
22
*.ftpignore
3-
connect.php
43
_config.yml
4+
core/constants/config.json

.htaccess

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Php infos/errors state show
2-
php_value display_errors 0
2+
php_value display_errors 1
33
php_flag output_buffering off
44

55
# Disable index of

README.md

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -41,63 +41,25 @@
4141

4242
### Database connection
4343

44-
After cloning the repository **you need to create the database connection file in the `/core` directory which will be called `connect.php` with inside**:
45-
46-
```php
47-
abstract class DataBase {
48-
/**
49-
* disconnect to the database
50-
* @return void
51-
*/
52-
public static function disconnect(): void {
53-
self::$bdd['db'] = NULL;
54-
return;
44+
After cloning the repository **you need to create the database json config file in the `/core/constants` directory which will be called `config.json` with inside**:
45+
46+
```json
47+
{
48+
"database": {
49+
"host": "localhost",
50+
"name": "id8823866_cv",
51+
"char": "utf8",
52+
"user": "id8823866_root",
53+
"pass": "~75rRTijOvE<bkte"
5554
}
56-
57-
/**
58-
* connect to the database
59-
* @return object[PDO] database object
60-
*/
61-
public static function connect(): PDO {
62-
try {
63-
self::$bdd['db'] = new PDO(
64-
'mysql:host='.self::$bdd['host'].'; dbname='.self::$bdd['name'].'; charset='.self::$bdd['char'],
65-
self::$bdd['user'],
66-
self::$bdd['pass'],
67-
[ PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING ]
68-
);
69-
}
70-
71-
catch(Exception $e) {
72-
die("[Err]:[{$e->getmessage()}]");
73-
}
74-
75-
return self::$bdd['db'];
76-
}
77-
78-
// Data Base auth fields
79-
private static $bdd = [
80-
"db" => NULL,
81-
"host" => "...",
82-
"name" => "...",
83-
"char" => "utf8",
84-
"user" => "...",
85-
"pass" => "..."
86-
];
8755
}
8856
```
8957

90-
**Don't forget to import the `capteur.sql` file into your database !**
91-
92-
---
93-
94-
## **To do list**
95-
96-
- [ ] ...
58+
**Don't forget to import the `cv.sql` file into your database !**
9759

9860
---
9961

100-
## Dernière MàJ
62+
## **Last Updates**
10163

10264
### Apr 28, 2020
10365

_config.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

core/connect.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Auteur : CARDINAL Florian
4+
* Date : 18/03/2020 10:52
5+
* Page : connect.php
6+
*/
7+
8+
/**
9+
* CV Data Base
10+
*/
11+
abstract class DataBase {
12+
// CV database handle
13+
private static $bdd = NULL;
14+
15+
// CV auth informations
16+
private static $auth = [];
17+
18+
/**
19+
* disconnect to CV the data base
20+
* @return void
21+
*/
22+
public static function disconnect(): void {
23+
self::$bdd = NULL;
24+
25+
return;
26+
}
27+
28+
/**
29+
* connect to the CV data base
30+
* @return object[PDO] data base object
31+
*/
32+
public static function connect(): PDO {
33+
try {
34+
self::$auth = json_decode(file_get_contents("./core/constants/config.json"), true)["database"];
35+
36+
self::$bdd = new PDO(
37+
'mysql:host='.self::$auth['host'].'; dbname='.self::$auth['name'].'; charset='.self::$auth['char'],
38+
self::$auth['user'],
39+
self::$auth['pass'],
40+
[ PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING ]
41+
);
42+
}
43+
44+
catch(Exception $e) {
45+
die("[Err]:[{$e->getmessage()}]");
46+
}
47+
48+
return self::$bdd;
49+
}
50+
}
51+
52+
/**
53+
* END
54+
*/

core/constants/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Constants
2+
3+
here you store any constants on json file like database connection, metadata, etc...

0 commit comments

Comments
 (0)