id, $object -> lastSave, $fullJSON, $object -> timeWatchM, $object -> timeWatchW, $object -> timeWatchD, $object -> countWatchM, $object -> countWatchW, $object -> countWatchD]; } $databaseAddress = "127.0.0.1"; $databasePort = "3306"; $databaseName = "u517357132_genderwatchpro"; $databaseUser = "u517357132_genderwatchpro"; $databasePassword = "zU!7gRHA6x"; $link = mysqli_connect($databaseAddress, $databaseUser, $databasePassword, $databaseName); if (!$link) { die('Could not connect to Database: ' . mysql_error()); } //if connection is successfully you will see message below echo 'Connected successfully to Database
'; mysqli_close($link); //$mysqli = new mysqli($databaseAddress, $databaseUser, $databasePassword, $databaseName); function saveToDatabase($contentArray, $mysqli) { echo "sending Query to Database
"; $response = mysqli_query($mysqli, "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]"); echo "Query sent
"; echo $response; return $response; } function getFromDatabase() { return []; } $entityBody = '{"lastSave": 0, "timeWatchM": 0, "timeWatchW": 0, "timeWatchD": 0, "countWatchM": 0, "countWatchW": 0, "countWatchD": 0, "id":"test","watches":[{"actions":[]},{"actions":[]},{"actions":[]}]}'; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $entityBody = file_get_contents('php://input'); $entityBodyObject = json_decode($entityBody); echo "POST Request received.
"; if(property_exists($entityBodyObject, "id")) { saveToDatabase(objectToArray($entityBodyObject, $entityBody), $link); echo "
Data saved.
"; } } elseif($_SERVER['REQUEST_METHOD'] === 'GET') { download_xlsxFile(getFromDatabase()); } else { echo "invalid Request.
Type: ".$_SERVER['REQUEST_METHOD']; } mysqli_close( );