change to SQL
This commit is contained in:
@@ -13,15 +13,22 @@ function objectToArray($object, $fullJSON) {
|
||||
$object -> countWatchD];
|
||||
}
|
||||
|
||||
function findRowIndex($id, $data) {
|
||||
$rowCounter = -1;
|
||||
foreach ($data as $row) {
|
||||
$rowCounter ++;
|
||||
if($row[0] == $id) {
|
||||
return $rowCounter;
|
||||
}
|
||||
}
|
||||
return $rowCounter + 1;
|
||||
$databaseAddress = "127.0.0.1";
|
||||
$databasePort = "3306";
|
||||
$databaseName = "u517357132_genderwatchpro";
|
||||
$databaseUser = "u517357132_genderwatchpro";
|
||||
$databasePassword = "zU!7gRHA6x";
|
||||
$mysqli = new mysqli($databaseAddress, $databaseUser, $databasePassword, $databaseName);
|
||||
|
||||
|
||||
$mysqli = new mysqli($databaseAddress, $databaseUser, $databasePassword, $databaseName);
|
||||
|
||||
function saveToDatabase($contentArray, $mysqli) {
|
||||
$mysqli->query("INSERT INTO `u517357132_genderwatchpro` (`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]");
|
||||
}
|
||||
|
||||
function getFromDatabase() {
|
||||
|
||||
}
|
||||
|
||||
$entityBody = '{"lastSave": 0, "timeWatchM": 0, "timeWatchW": 0, "timeWatchD": 0, "countWatchM": 0, "countWatchW": 0, "countWatchD": 0, "id":"test","watches":[{"actions":[]},{"actions":[]},{"actions":[]}]}';
|
||||
@@ -32,20 +39,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
echo "POST Request received.<br>";
|
||||
|
||||
if(property_exists($entityBodyObject, "id")) {
|
||||
$data = read_xls_file($fileName);
|
||||
|
||||
foreach ($data as $row) {
|
||||
echo "new Row: <br>";
|
||||
foreach ($row as $cell) {
|
||||
echo $cell." ";
|
||||
}
|
||||
}
|
||||
|
||||
$rowIndex = findRowIndex($entityBodyObject->id, $data);
|
||||
$data[$rowIndex] = objectToArray($entityBodyObject, $entityBody);
|
||||
write_xlsxFile($fileName, $data);
|
||||
saveToDatabase(objectToArray($entityBodyObject, $entityBody), $mysqli);
|
||||
echo "<br>Data saved.<br>";
|
||||
}
|
||||
} elseif($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
download_xlsxFile(getFromDatabase());
|
||||
} else {
|
||||
echo "invalid Request.<br> Type: ".$_SERVER['REQUEST_METHOD'];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user