Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Aufruf von PHP-Skript mit C# (Unity)

Lassen Sie mich versuchen, dies in ein funktionierendes Beispiel umzuschreiben:

C#

void Start() {
    StartCoroutine(GetData());
}


IEnumerator GetData() {
    gameObject.guiText.text = "Loading...";
    WWW www = new WWW("http://yoururl.com/yourphp.php?table=shoes"); //GET data is sent via the URL

    while(!www.isDone && string.IsNullOrEmpty(www.error)) {
        gameObject.guiText.text = "Loading... " + www.Progress.ToString("0%"); //Show progress
        yield return null;
    }

    if(string.IsNullOrEmpty(www.error)) gameObject.guiText.text = www.text;
    else Debug.LogWarning(www.error);
}

PHP

<?php

//DB connection goes here

if ($_REQUEST['table'] === "shoes") { //I'm using REQUEST instead of GET, so it will work with both GET and POST
    $query = "SELECT * FROM `shoes` ORDER by `price` ASC LIMIT 10";
} elseif ($_REQUEST['table'] === "sneakers") { 
    $query = "SELECT * FROM `sneakers` ORDER by `price` ASC LIMIT 10";
}

$result = mysql_query($query) or die(mysql_error());

while ($row = mysql_fetch_assoc($result)) {
    echo  $row['shopname'] . "\t" . $row['price'] . "\n"; 
}
?>

Hoffe, das hilft!