change to SQL
This commit is contained in:
parent
973e5da155
commit
e797580812
|
@ -18,22 +18,19 @@ $databasePort = "3306";
|
||||||
$databaseName = "u517357132_genderwatchpro";
|
$databaseName = "u517357132_genderwatchpro";
|
||||||
$databaseUser = "u517357132_genderwatchpro";
|
$databaseUser = "u517357132_genderwatchpro";
|
||||||
$databasePassword = "zU!7gRHA6x";
|
$databasePassword = "zU!7gRHA6x";
|
||||||
$link = mysqli_connect($databaseAddress, $databaseUser, $databasePassword, $databaseName);
|
$conn = new mysqli($databaseAddress, $databaseUser, $databasePassword, $databaseName);
|
||||||
if (!$link) {
|
// Check connection
|
||||||
die('Could not connect to Database: ' . mysql_error());
|
if ($conn->connect_error) {
|
||||||
|
die("Connection failed: " . $conn->connect_error);
|
||||||
}
|
}
|
||||||
//if connection is successfully you will see message below
|
|
||||||
echo 'Connected successfully to Database<br>';
|
|
||||||
|
|
||||||
mysqli_close($link);
|
function saveToDatabase($contentArray, $conn) {
|
||||||
//$mysqli = new mysqli($databaseAddress, $databaseUser, $databasePassword, $databaseName);
|
|
||||||
|
|
||||||
function saveToDatabase($contentArray, $mysqli) {
|
|
||||||
echo "sending Query to Database<br>";
|
echo "sending Query to Database<br>";
|
||||||
$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]");
|
$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 "Query sent<br>";
|
echo "Query sent<br>";
|
||||||
echo $response;
|
echo $result;
|
||||||
return $response;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFromDatabase() {
|
function getFromDatabase() {
|
||||||
|
@ -48,7 +45,7 @@ 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")) {
|
||||||
saveToDatabase(objectToArray($entityBodyObject, $entityBody), $link);
|
saveToDatabase(objectToArray($entityBodyObject, $entityBody), $conn);
|
||||||
echo "<br>Data saved.<br>";
|
echo "<br>Data saved.<br>";
|
||||||
}
|
}
|
||||||
} elseif($_SERVER['REQUEST_METHOD'] === 'GET') {
|
} elseif($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||||
|
@ -59,6 +56,5 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$conn->close();
|
||||||
mysqli_close( );
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue