-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.inc.php
More file actions
34 lines (30 loc) · 925 Bytes
/
db.inc.php
File metadata and controls
34 lines (30 loc) · 925 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
34
<?php
function connectToDB()
{
$env = parse_ini_file('.env');
$db_host = $env["DB_HOST"];
$db_user = $env["DB_USER"];
$db_password = $env["DB_PASSWORD"];
$db_db = $env["DB_DB"];
$db_port = $env["DB_PORT"];
try {
$db = new PDO('mysql:host=' . $db_host . '; port=' . $db_port . '; dbname=' . $db_db, $db_user, $db_password);
} catch (PDOException $e) {
echo "Error!: " . $e->getMessage() . "<br />";
die();
}
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
return $db;
}
function newAppointment(String $name, String $email, String $appdate): bool|int
{
$db = connectToDB();
$sql = "INSERT INTO appointments(name, email, appdate) VALUES (:name, :email, :appdate)";
$stmt = $db->prepare($sql);
$stmt->execute([
'name' => $name,
'email' => $email,
'appdate' => $appdate
]);
return $db->lastInsertId();
}