change to SQL
This commit is contained in:
parent
20618367e0
commit
67c5550de6
|
@ -13,15 +13,22 @@ function objectToArray($object, $fullJSON) {
|
||||||
$object -> countWatchD];
|
$object -> countWatchD];
|
||||||
}
|
}
|
||||||
|
|
||||||
function findRowIndex($id, $data) {
|
$databaseAddress = "127.0.0.1";
|
||||||
$rowCounter = -1;
|
$databasePort = "3306";
|
||||||
foreach ($data as $row) {
|
$databaseName = "u517357132_genderwatchpro";
|
||||||
$rowCounter ++;
|
$databaseUser = "u517357132_genderwatchpro";
|
||||||
if($row[0] == $id) {
|
$databasePassword = "zU!7gRHA6x";
|
||||||
return $rowCounter;
|
$mysqli = new mysqli($databaseAddress, $databaseUser, $databasePassword, $databaseName);
|
||||||
}
|
|
||||||
}
|
|
||||||
return $rowCounter + 1;
|
$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":[]}]}';
|
$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>";
|
echo "POST Request received.<br>";
|
||||||
|
|
||||||
if(property_exists($entityBodyObject, "id")) {
|
if(property_exists($entityBodyObject, "id")) {
|
||||||
$data = read_xls_file($fileName);
|
saveToDatabase(objectToArray($entityBodyObject, $entityBody), $mysqli);
|
||||||
|
|
||||||
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);
|
|
||||||
echo "<br>Data saved.<br>";
|
echo "<br>Data saved.<br>";
|
||||||
}
|
}
|
||||||
|
} elseif($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||||
|
download_xlsxFile(getFromDatabase());
|
||||||
} else {
|
} else {
|
||||||
echo "invalid Request.<br> Type: ".$_SERVER['REQUEST_METHOD'];
|
echo "invalid Request.<br> Type: ".$_SERVER['REQUEST_METHOD'];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
require $_SERVER['DOCUMENT_ROOT'] . '/spreadSheetReader/SimpleXLSX.php';
|
require $_SERVER['DOCUMENT_ROOT'] . '/spreadSheetReader/SimpleXLSX.php';
|
||||||
require $_SERVER['DOCUMENT_ROOT'] . '/spreadSheetReader/SimpleXLSXGen.php';
|
require $_SERVER['DOCUMENT_ROOT'] . '/spreadSheetReader/SimpleXLSXGen.php';
|
||||||
function read_xls_file($filename){
|
|
||||||
$fileContent = [];
|
|
||||||
if ($xlsx = SimpleXLSX::parse($filename)) {
|
|
||||||
$fileContent = ($xlsx->rows());
|
|
||||||
} else {
|
|
||||||
echo SimpleXLSX::parseError();
|
|
||||||
}
|
|
||||||
return $fileContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
function download_xlsxFile($data) {
|
||||||
function write_xlsxFile($filename, $data) {
|
|
||||||
$xlsx = SimpleXLSXGen::fromArray($data);
|
$xlsx = SimpleXLSXGen::fromArray($data);
|
||||||
$xlsx->saveAs($filename);
|
$xlsx->downloadAs("data.xlsx");
|
||||||
}
|
}
|
Loading…
Reference in New Issue