connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO Outputs (name, board, gpio, state)
VALUES ('" . $name . "', '" . $board . "', '" . $gpio . "', '" . $state . "')";
if ($conn->query($sql) === TRUE) {
return "New output created successfully";
}
else {
return "Error: " . $sql . "
" . $conn->error;
}
$conn->close();
}
function deleteOutput($id) {
global $servername, $username, $password, $dbname;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "DELETE FROM Outputs WHERE id='". $id . "'";
if ($conn->query($sql) === TRUE) {
return "Output deleted successfully";
}
else {
return "Error: " . $sql . "
" . $conn->error;
}
$conn->close();
}
function updateOutput($id, $state) {
global $servername, $username, $password, $dbname;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE Outputs SET state='" . $state . "' WHERE id='". $id . "'";
if ($conn->query($sql) === TRUE) {
return "Output state updated successfully";
}
else {
return "Error: " . $sql . "
" . $conn->error;
}
$conn->close();
}
function getAllOutputs() {
global $servername, $username, $password, $dbname;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, name, board, gpio, state FROM Outputs ORDER BY board";
if ($result = $conn->query($sql)) {
return $result;
}
else {
return false;
}
$conn->close();
}
function getAllOutputStates($board) {
global $servername, $username, $password, $dbname;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT gpio, state FROM Outputs WHERE board='" . $board . "'";
if ($result = $conn->query($sql)) {
return $result;
}
else {
return false;
}
$conn->close();
}
function getOutputBoardById($id) {
global $servername, $username, $password, $dbname;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT board FROM Outputs WHERE id='" . $id . "'";
if ($result = $conn->query($sql)) {
return $result;
}
else {
return false;
}
$conn->close();
}
function updateLastBoardTime($board) {
global $servername, $username, $password, $dbname;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE Boards SET last_request=now() WHERE board='". $board . "'";
if ($conn->query($sql) === TRUE) {
return "Output state updated successfully";
}
else {
return "Error: " . $sql . "
" . $conn->error;
}
$conn->close();
}
function getAllBoards() {
global $servername, $username, $password, $dbname;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT board, last_request FROM Boards ORDER BY board";
if ($result = $conn->query($sql)) {
return $result;
}
else {
return false;
}
$conn->close();
}
function getBoard($board) {
global $servername, $username, $password, $dbname;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT board, last_request FROM Boards WHERE board='" . $board . "'";
if ($result = $conn->query($sql)) {
return $result;
}
else {
return false;
}
$conn->close();
}
function createBoard($board) {
global $servername, $username, $password, $dbname;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO Boards (board) VALUES ('" . $board . "')";
if ($conn->query($sql) === TRUE) {
return "New board created successfully";
}
else {
return "Error: " . $sql . "
" . $conn->error;
}
$conn->close();
}
function deleteBoard($board) {
global $servername, $username, $password, $dbname;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "DELETE FROM Boards WHERE board='". $board . "'";
if ($conn->query($sql) === TRUE) {
return "Board deleted successfully";
}
else {
return "Error: " . $sql . "
" . $conn->error;
}
$conn->close();
}
?>