1

我正在为我的项目使用 Arduino Yun。我需要从 web 主机、000webhost、mysql 数据库下载数据到我的 Arduino Yun。我怎样才能做到这一点?我想使用 php 文件,它应该独立工作。我该如何站在阿杜诺云这边。这是我的 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 中获取所有数据?

4

0 回答 0