-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbconnection.php
38 lines (33 loc) · 1.29 KB
/
dbconnection.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
37
38
<?php
$servername = "xxxx"; // IP address to your server
$username = "xxxx"; // Username to your database
$password = "xxxx"; // Password to your database
$dbname = "xxxx"; // Database name
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("DB Connection failed: " . $conn->connect_error);
} else {
debug("DB Connection Successful");
// Check if the table exists
$checkTableQuery = "SHOW TABLES LIKE 'temperatureDataF'";
$result = $conn->query($checkTableQuery);
if ($result->num_rows == 0) {
// Create table if it doesn't exist
$sqlStructure = "CREATE TABLE temperatureDataF (
id int(11) NOT NULL AUTO_INCREMENT,
time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
temperature varchar(50) COLLATE utf8_unicode_ci NOT NULL,
measurement varchar(1) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (id)) COLLATE='utf8_unicode_ci'";
if ($conn->query($sqlStructure) === TRUE) {
debug("Table structure created successfully");
} else {
debug("Error creating table structure: " . $conn->error);
}
} else {
debug("Table 'temperatureDataF' already exists, not creating");
}
}
?>