2016-06-10 131 views
-2

我正在开发一个将用于发送短信的应用程序。立即应用程序从另一个应用程序获取所需的值,并且应该立即发送消息AUTOMATICALLY。我希望有人能指导我如何使它自动化。如果我选择一个ID正在工作,但我希望自动发送而不重复。php mysql数据库只读取一次数据

//I would want to have like an automatic retrieval any time it gets 
$sql = "SELECT name,amount, trans_id, msisdn, time_paid FROM customer"; 

$result1 = mysqli_query($conn, $sql); 
$resultarr = mysqli_fetch_assoc($result1); // fetch data 

$name = $resultarr['name']; // get the name from an array 
$amount = $resultarr['amount']; // get the amount from the array 
$transaction_id = $resultarr['trans_id']; // get the transaction id from the array 
$date = $resultarr['time_paid']; // get time paid from array 

$conn->close(); 

//the message to be sent 
$message = "Dear $name we have received $amount from you. MPESA  transaction Id $transaction_id on $date"; 

$mobilenumber = $resultarr['msisdn']; // get mobile number from array 
$message_sent = $message; 

$serviceArguments = array(
     "mobilenumber" => $mobilenumber, 
     "message" => $message_sent 
     ); 
+1

把它放在cron上?每分钟运行一次,但对于这种听起来相当公平的用例,尤其是如果您在单个进程中执行多个代码而不是您的代码所暗示的情况。 –

+0

您应该将其构建为可以被其他程序调用的服务,而不是作为数据库驱动的解决方案 – Jens

+0

好吧,我正在从另一个程序获取详细信息,并且希望它在获取它们时自动发送消息。请问,我该如何处理这项服务? @Jens –

回答

1

在您的服务器上设置一个cron作业,它将帮助您自动发送短信。