-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.php
37 lines (28 loc) · 1007 Bytes
/
connection.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
function Connect()
{
$dbhost = "127.0.0.1";
$dbport = 3369;
$dbuser = "root";
$dbpass = ""; // Replace this with your database password
$dbname = "foodorder";
try {
// Create Connection
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname, $dbport);
if ($conn->connect_error) {
throw new Exception("Connection failed: " . $conn->connect_error);
}
return $conn;
} catch (mysqli_sql_exception $e) {
// Handle the exception related to the database connection.
echo "<p>Caught an exception: " . $e->getMessage() . "</p>";
return null; // You can decide how to handle the failure in your application.
} catch (Exception $e) {
// Handle other general exceptions here.
echo "<p>Caught a general exception: " . $e->getMessage() . "</p>";
return null; // You can decide how to handle this as well.
}
}
// Call the Connect() function
$conn = Connect();
?>