Skip to content
Advertisement

UnityWebRequest(path, UnityWebRequest.kHttpVerbGET): how add a variable to the request to retrieve a specific mysql row?

I currently retrieve all data from db with my sql query below by sending request to server’s php file.

I need to post to the php file a variable as criteria for this mysql request, e.g WHERE carName=”Somecar” AND slice=3. How can I add the criteria to my request and can I continue to still use the UnityWebRequest.kHttpVerbGET and the ToFileDownloadHandler below?

Current Unity request:

Debug.Log("Retrieving existing data from server.");
        UnityWebRequest myWebRequest = new UnityWebRequest(path, UnityWebRequest.kHttpVerbGET);
        
        myWebRequest.downloadHandler = new ToFileDownloadHandler(new byte[64 * 1024], savePathWithFileName);
        yield return myWebRequest.SendWebRequest();

And php:

$stmt = $conn->prepare("SELECT id, carName, thisCarImg, i_width, i_heigth, i_depth, b_width, b_heigth, b_depth, f_depth, m_width, m_heigth, i_date, slope, slice, slopeName, sliceName FROM $myTable")
$stmt->execute();

The best I could think is adding php as an additional tag although the question is how to add a form to Unity’s query – using the form received in php is a different matter.

Advertisement

Answer

you have to add the parameters in path

eg. sample.php?Somecar=122&slice=1

This way you can achieve this unity input in API call to PHP on GET request, if you are using POST then you can use WWWForm class.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement