Fetching Mysql data with UnityWebRequest.Get is not working

I am trying to fetch data from a database with UnityWebRequest.

This is how I’ve set up my function inside of Unity:

    public string[] comments;
    public string requestUrl = "http://creativiii.com/architect/data.php?action=retrieve&model_nameGet=test";
    public IEnumerator Retrieve()
    {

        using (UnityWebRequest webRequest = UnityWebRequest.Get(requestUrl))
        {
            // Request and wait for the desired page.
            yield return webRequest.SendWebRequest();
            if (webRequest.isNetworkError)
            {
                Debug.Log("Error: " + webRequest.error);
            }
            else
            {
                Debug.Log("Received: " + webRequest.downloadHandler.text);
                string fulldata = webRequest.downloadHandler.text;
                comments = fulldata.Split(new string[] { "
" }, StringSplitOptions.None);
                Debug.Log(String.Format("There are {0} comments.", comments.Length));
                foreach (string comment in comments)
                {
                    Debug.Log(comment);
                }
            }
        }
    }

And this is how the data.php file is set up:

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    if ($action_type == "retrieve") {

        $sql = " SELECT * FROM `ar_comments` WHERE `model_name` = '".$model_name_get."'";
        $result = $conn->query($sql);

        $push = "INSERT INTO `ar_comments`(`model_name`,`comment`,`position_x`,`position_y`,`position_z`) VALUES ('".$model_name."','".$comment."','".$position_x."','".$position_y."','".$position_z."')";

        if ($result->num_rows > 0) {
            // output data of each row
            while($row = $result->fetch_assoc()) {
                echo "Comment: " . $row["comment"]. " - Position: " . $row["position_x"]. ", " . $row["position_y"]. ", " . $row["position_z"]. "
";
            }
        } else {
            echo "0 results";
        }

    }

If I visit the URL from the first script it will correctly return the data I have requested.
However, If I request it from Unity, I will only receive:

0 results

Why is this happening? Is there something wrong with my C# code?

It seems your code is fine.

Here was what I got directly from your URL when I ran your code (unchanged) in Unity 2018.2.10:

I still get no results on my end.

Is Unity or PHP caching the results somehow? How can I fix this?

EDIT: I have tried forcing Mysql to not cache and UnityWebRequest.ClearCookieCache() but neither worked.

Try printing webRequest.url after request, maybe the query got somehow corrupted.

I’m experiencing the same issue in version 2019.1.6

Interesting detail… it happens in PC but not in Mac

Have you tested that url in browser on the same PC where you testing windows build? Ive checked and it works on my side both in unity and browser, I’m on windows now. Maybe the issue is coming from network configuration?