-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.php
32 lines (26 loc) · 784 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
<?php
require __DIR__ . '/vendor/autoload.php';
use Dotenv\Dotenv;
if (getenv('JAWSDB_URL')) {
$db = parse_url(getenv('JAWSDB_URL'));
$host = $db['host'];
$username = $db['user'];
$password = $db['pass'];
$database = ltrim($db['path'], '/');
$port = isset($db['port']) ? $db['port'] : 3306;
} else {
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
$host = $_ENV['DB_HOST'];
$username = $_ENV['DB_USERNAME'];
$password = $_ENV['DB_PASSWORD'];
$database = $_ENV['DB_DATABASE'];
$port = $_ENV['DB_PORT'];
}
// Create a new MySQLi connection
$conn = new mysqli($host, $username, $password, $database, $port);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>