我正在使用Arduino Yun作为我的项目。我需要从web主机,000webhost,mysql数据库下载数据到我的Arduino Yun。我怎样才能做到这一点?我想使用php文件,它应该独立工作。我应该如何在Arduino Yun方面。 这是我的PHP脚本代码:
<?php
$db_name = "00000";
$mysql_user = "0000";
$mysql_pass = "0000";
$server_name = "mysql9.000webhost.com";
$con = mysqli_connect($server_name,$mysql_user,$mysql_pass,$db_name);
$dname = $_GET["dname"];
$dlastname = $_GET["dlastname"];
$pname = $_GET["pname"];
$plastname = $_GET["plastname"];
$statement = mysqli_prepare($con, "SELECT * FROM drug WHERE dname = ? AND dlastname = ? AND pname = ? AND plastname = ?");
mysqli_stmt_bind_param($statement, "ssss", $dname, $dlastname, $pname, $plastname);
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $userID, $dname, $dlastname, $pname, $plastname, $drug, $time, $minute, $amount, $op);
$response = array();
$response["success"] = false;
while(mysqli_stmt_fetch($statement)){
$response["success"] = true;
$response["userID"] = $userID;
$response["dname"] = $dname;
$response["dlastname"] = $dlastname;
$response["pname"] = $pname;
$response["plastname"] = $plastname;
$response["drug"] = $drug;
$response["time"] = $time;
$response["minute"] = $minute;
$response["amount"] = $amount;
$response["op"] = $op;
}
//echo"Drug: ".$drug;
//echo"Hour: ".$time;
//echo"Minute: ".$minute;
//echo"Op: ".$op;
?>
基本上只需从Arduino获取输入:dname,dlastname,pname和plastname。然后搜索整个表格。如果这四列匹配,只需从Mysql数据库下载该行的全部信息。
两个问题: 1.如果php脚本没有问题,应该如何在Arduino yun中编写代码 2.如何从php文件下载数据?是否有类似返回的内容,以便我可以在Arduino Yun中获取所有数据?