php - 数据库行轮询服务
问题描述
我打算开发许多捕获以下内容的客户投票系统:
<?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;
}
解决方案
推荐阅读
- node.js - clearTimeout 测试不适用于 jest.useFakeTimers()
- r - R中混合数据采样的回归
- firebase - 有没有办法在颤振应用程序中使用firebase查找具有相同子名的孩子的总数?
- php - 如何测试 Laravel 中 JSON 文件中存在的嵌套 JSON 数据?
- powershell - 在 For Each 语句中过滤 Powershell 结果
- symfony - 如何在 Shopware 6 中使用多个队列工作者?
- android - 如何为 Android 应用程序中的多种登录方式构建活动/片段
- python - 熊猫:回顾过去
- python - MongoDB对属性的最接近匹配给出属性的一部分
- javascript - 如何使用重叠 div 获取当前悬停位置?