From 0dccb4bab2e4f57325408672bada679ec97564b9 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Wed, 15 Feb 2023 14:27:19 +0100 Subject: [PATCH] change to SQL --- dataCollector/dataCollector.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/dataCollector/dataCollector.php b/dataCollector/dataCollector.php index 722ea80..055b9df 100644 --- a/dataCollector/dataCollector.php +++ b/dataCollector/dataCollector.php @@ -28,14 +28,17 @@ if ($conn->connect_error) { function saveToDatabase($contentArray, $conn) { echo "sending Query to Database
"; -// $sql = "INSERT INTO `topics` (`id`, `fullJSON`, `timeWatchM`,`timeWatchW`, `timeWatchD`, `countWatchM`, `countWatchW`, `countWatchD`) values ($contentArray[0], $contentArray[2], $contentArray[3], $contentArray[4], $contentArray[5], $contentArray[6], $contentArray[7], $contentArray[8]) ON DUPLICATE KEY UPDATE `id` = $contentArray[0]"; - $sql = "INSERT INTO `topics` (`id`, `fullJSON`, `timeWatchM`,`timeWatchW`, `timeWatchD`, `countWatchM`, `countWatchW`, `countWatchD`) values ('".$contentArray[0]."', '".$contentArray[2]."', ".$contentArray[3].", ".$contentArray[4].", ".$contentArray[5].", ".$contentArray[6].", ".$contentArray[7].", ".$contentArray[8].") ON DUPLICATE KEY UPDATE `id` = '".$contentArray[0]."'"; + $sql = "SELECT * FROM `topics` WHERE id='".$contentArray[0]."'"; $result = $conn->query($sql); - echo "Query sent
Result: " . $result; + echo "Select Query sent
Result: " . $result; if($result === 0) { + $sql = "INSERT INTO `topics` (`id`, `fullJSON`, `timeWatchM`,`timeWatchW`, `timeWatchD`, `countWatchM`, `countWatchW`, `countWatchD`) values ('".$contentArray[0]."', '".$contentArray[2]."', ".$contentArray[3].", ".$contentArray[4].", ".$contentArray[5].", ".$contentArray[6].", ".$contentArray[7].", ".$contentArray[8].") ON DUPLICATE KEY UPDATE `id` = '".$contentArray[0]."'"; + $result = $conn->query($sql); + echo "Insert Query sent
Result: " . $result; + } else { $sql = "UPDATE `topics` SET `id`='".$contentArray[0]."',`lastSave`='".$contentArray[1]."',`fullJSON`='".$contentArray[2]."',`timeWatchM`='".$contentArray[3]."',`timeWatchW`='".$contentArray[4]."',`timeWatchD`='".$contentArray[5]."',`countWatchM`='".$contentArray[6]."',`countWatchW`='".$contentArray[7]."',`countWatchD`='".$contentArray[8]."' WHERE `id` = '".$contentArray[0]."'"; $result = $conn->query($sql); - echo "Query sent
Result: " . $result; + echo "Update Query sent
Result: " . $result; } return; }