-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.php
36 lines (33 loc) · 954 Bytes
/
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
35
36
<?php
/**
* AntenneBergstrasse API Adapater
* Basic database manager
*
* @author Benjamin Haettasch (bhaettasch)
* @version 0.1
*/
//Load settings
require_once("settings.php");
/**
* Create a database conneciton object to the specified database
*
* @param $db_name string identifier of the database in settings object
* @return mysqli mysqli connection object for the specified database
*/
function db_connect($db_name)
{
global $databases;
if(isset($databases[$db_name]) && is_array($databases[$db_name]))
{
// Create connection
$conn = new mysqli(SERVERNAME, $databases[$db_name]["user"], $databases[$db_name]["password"], $databases[$db_name]["name"]);
// Check connection
if ($conn->connect_error) {
die("Connection failed (Database error): " . $conn->connect_error);
}
return $conn;
}
else
die("Connection failed - database does not exist");
}
?>