-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconnection.php
More file actions
33 lines (28 loc) · 754 Bytes
/
connection.php
File metadata and controls
33 lines (28 loc) · 754 Bytes
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
<?php
require_once __DIR__ . "/vendor/autoload.php";
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
$serverName = $_ENV['DB_SERVER'];
$userName = $_ENV['DB_USERNAME'];
$password = $_ENV['DB_PASSWORD'];
$dbName = $_ENV['DB_NAME'];
function connection($con)
{
if ($con->connect_error) {
die("Connection Failed: " . $con->connect_error);
}
echo "Database Connected";
return $con;
}
function connectWithDb($dbName)
{
global $serverName, $userName, $password;
$con = new mysqli($serverName, $userName, $password, $dbName);
connection($con);
}
function connectWithoutDb()
{
global $serverName, $userName, $password;
$con = new mysqli($serverName, $userName, $password);
connection($con);
}