-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.php
More file actions
52 lines (47 loc) · 1.42 KB
/
db.php
File metadata and controls
52 lines (47 loc) · 1.42 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
<?php
/**
* Database choosing file
*
* Select the right database via getDatabase($db, $pdo = false)
* Multidatabase support
*
* PHP version 5
*
*
* @category Colorcompare
* @package Marker
* @author Thomas Störzner <tom@tstl.de>
* @author Thomas Störzner <tom@tstl.de>
* @copyright 2016-2017 TSTL
* @license MIT
* @version 0.1
* @since File available since Release 0.1
*/
//Datenbank auswählen
error_reporting(0);
function getDatabase($db, $pdo = false) {
$user;
$password;
$database;
$host = "localhost";
switch ($db) { //db durch $db_main = getDatabase('dbname') auswählen
case 'colorcompare': //firealarm = Hauptdatenbank
$user = 'colorcompare';
$password = 'SECUREPASSWORT'; //insert your database password here
$database = 'colorcompare';
break;
}
//platz für mehr datenbanken (cases)
$db = null;
if ($pdo) {
$db = new PDO("mysql:host=$host;dbname=$database;charset=UTF8", $user, $password); //Verbinden mit PDO ($pdo = true)
} else {
$db = new mysqli($host, $user, $password, $database); //Verbinden mit mysqli
$db->set_charset("utf8"); //UTF8 encriptopn
if ($db->connect_errno) { //Fehler beim Verbinden abfangen
echo "Failed to connect to MySQL: (" . $db->connect_errno . ") " . $db->connect_error;
}
}
return $db;
}
?>