<?php
try
{
// Check Authentication
require "database.php";
$json = file_get_contents("php://input");
$List1 = array();
$List1 = json_decode($json, true);
if (empty($List1))
{
// Return JSON to client
header('HTTP/1.1 400 Bad Request');
header('Content-Type: application/json');
$data = array("result" => -1, "message" => "failed", "error" => "Error Empty List");
print json_encode ($data);
exit;
}
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Check user name and password
$x = 0; // Start reading from 1st row
while($x < count($List1))
{
$Map1 = array();
$Map1 = $List1[$x];
$sku = $Map1["sku"];
$desc = $Map1["desc"];
$price = $Map1["price"];
// Insert or Update products
$query = "REPLACE INTO `tbl_products` (`product_code`, `product_price`, `descriptions`)";
$query .= " VALUES (:sku, :price, :desc)";
$db = $pdo->prepare($query);
$db->bindvalue(":sku", $sku, PDO::PARAM_STR);
$db->bindvalue(":price", $price, PDO::PARAM_STR);
$db->bindvalue(":desc", $desc, PDO::PARAM_STR);
$db->execute();
$x++;
}
Database::disconnect();
// Return JSON to client
header('HTTP/1.1 200 OK');
header('Content-Type: application/json');
$data = array("result" => 0, "message" => "success", "error" => null);
print json_encode ($data);
}
catch (PDOException $e)
{
// Log errors to database
//$this->LogErrorToDB($e->getMessage());
Database::disconnect();
// Return JSON to client
header('HTTP/1.1 500 Internal Server Error');
header('Content-Type: application/json');
$data = array("result" => -1, "message" => "failed", "error" => "Error Execute Query");
print json_encode ($data);
}
?>