首页 > 解决方案 > 数据库行轮询服务

问题描述

我打算开发许多捕获以下内容的客户投票系统:

<?php

    $data = array(
          'vancancy' => 'PE',
    'pollingStation' => 'PS1001',
        'validVotes' => '400',
     'rejectedVotes' => '10',
        'validVotes' => '400',
       'base64Image' => 'VVVGGFTFTFHNBFVUWWSETD',
       'candidate 1' => '200',
       'candidate 2' => '100',
       'candidate 3' => '190',
       'base64Image' => 'VVVGGFTFTFHNBFVUWWSETD');

    $payload = json_encode($data);


    $url = 'http://localhost/APIS/RMS/jsonapi.php';
    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content- 
  Type:application/json'));

    $response = curl_exec($ch);
    echo $response;
    curl_close($ch);
    ?>

在完成发布的中央服务器上;我有 STAGING 数据库表,它接收 json 数据并将其保存为 TEXT。

我想要一个服务,它应该定期轮询 STAGING 表并将 json TEXT 拆分为单独的字段以填充另一个结果表(存储候选人 1、2、3 和票数。读取每一行后,然后在暂存中设置一个标志表必须设置,所以我再次阅读。在结果表中,我必须计算每个候选人在另一个总票数中的票数。

@@@@@@@@@@@ 这是从客户端接收结果的 API 代码@@@@@@@@@

<?php
header("Content-Type:application/json");
require 'checkSQLInsertion.php';

// read the incoming POST body (the JSON)
$input = file_get_contents('php://input');

if($input) 
{
$SQLInsertStatus=get_insertStatus($input);

if($SQLInsertStatus)
{
    response(200,1);//No SQL Insertion
}
else
{
    response(200,0); //Successful SQL Insetion
}

}
else
{
response(400,"If you can see this, then Web Service is Working, try 
again!! ");
}

function response($status,$ack)
{
header("HTTP/1.1 ".$status);

$response['status']=$status;
$response['status_message']=$ack;

$json_response = json_encode($response);
echo $json_response;
}

标签: phpmysql

解决方案


推荐阅读