Here is the code snippet [ for PHP, Slim Framework on server side ]
In routes.php
To fetch data
$app->get('/tablename/connection', function (Request $request, Response $response)
{
$db = $this->get(PDO::class);
$sql = "SELECT sendstatus FROM tablename";
$exec_sql = $db->prepare($sql);
$exec_sql->execute();
$data = $exec_sql->fetchAll(PDO::FETCH_ASSOC);
$data_encode = json_encode($data);
$response->getBody()->write($data_encode);
return $response->withHeader('Content-Type', 'application/json');
});
To post data
$app->post('/tablename/insertVehicleEnquiry', function (request $request, response $response)
{
$db = $this->get(PDO::class);
$data = json_decode($data, true);
$fieldpk = isset( data[0] ["fieldpk"] ) ? $data[0]["fieldpk"] : null ;
$field1 = isset( $data[0]["field1"] ) ? $data[0]["field1"] : null ;
$query = "INSERT INTO tablename_header ( " ;
$query = $query . "fieldpk)" ;
$query = $query . "VALUES (" ;
$query = $query . "'".$vehicleenquiryheaderpk_header."') ";
$exec_sql = $db->prepare($query);
try
{
$exec_sql->execute();
$recordcount_header_check = $recordcount_header_check + 1 ;
}
catch(PDOException $return_errorMessage)
{
$db->rollBack();
$return_arr[] = array('return_status' => 400,
'success_message' => '',
'error_message' => $return_errorMessage->getMessage()
);
$data_encode = json_encode($return_arr);
$data_encode = encrypt_decrypt('encrypt', $data_encode);
$response->getBody()->write($data_encode);
return $response->withHeader('Content-Type', 'application/json');
}
$db->commit();
$return_arr[] = array('return_status' => 200,
'success_message' => 'Successful',
'error_message' => ''
);
$data_encode = json_encode($return_arr);
$data_encode = encrypt_decrypt('encrypt', $data_encode);
$response->getBody()->write($data_encode);
return $response->withHeader('Content-Type', 'application/json');
);
I've simplified the server side code to a maximum extend. For this, you need to go through Slim framework, IMO.
HTH