-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabase.php
64 lines (51 loc) · 1.65 KB
/
Database.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
class SETRAM_Database {
public $connexion, $Db_name;
public function __construct($Db_name) {
$this->Db_name = $Db_name;
}
public function get_connex() {
return $this->connexion;
}
public function Connection_to_Server() {
$host = '';
$dbname = '';
$user = '';
$password = 'place-holder-not-my-real-password';
$this->connexion = new PDO("mysql:host=$host;dbname=$dbname",$user,$password);
if (!$this->connexion) {
// echo "Connection error <br>";
} else {
// echo "Connected successfully <br>";
}
}
public function Connection_to_Db() {
$host = '';
$dbname = '';
$user = '';
$password = 'place-holder-not-my-real-password';
$this->connexion = new PDO("mysql:host=$host;dbname=$dbname", $user, $password);
if (!$this->connexion) {
// echo "Connection error: " . print_r($this->connexion->errorInfo(), true) . "<br>";
} else {
// echo "Connected successfully <br>";
}
return $this->connexion;
}
public function SETRAM_Database_Creation() {
$Request = "CREATE DATABASE IF NOT EXISTS " . $this->Db_name;
$x = $this->connexion->prepare($Request);
$Se = $x->execute();
if (!$Se) {
// echo "Database creation error creation error: " . print_r($x->errorInfo(), true) . "<br>";
} else {
// echo "Database created successfully <br>";
}
}
}
//////// USAGE /////////
$db = new SETRAM_Database("");
$db->Connection_to_Server();
$db->SETRAM_Database_Creation();
$connection = $db->Connection_to_Db();
////////////////////////