I am setting up a SQL server database and want to store continuous data from my Unity app while running through HTTP request.
I am using Unitywebrequest.post to send the data to the database through coroutine call. However, this only allows the data to be transferred one time.
Is there any other way Unitywebrequest.post can be used to send the data other than calling it through coroutine?
I tried to put Unitywebrequest.post in Update function to allow continuous increment data to be sent to the database while the app is running. But, the data that were logged in the database is not incremented properly as expected.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class StoreData : MonoBehaviour
{
int intDummyValue = 0;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
updateDummyInt();
Upload(intDummyValue.toString());
}
private void updateDummyInt()
{
intDummyValue += 1;
}
private void Upload(string dummy1)
{
WWWForm form = new WWWForm();
form.AddField("intDummy", dummy1);
UnityWebRequest www = UnityWebRequest.Post("http://localhost/logToDB.php", form);
www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log("error is " + www.error);
}
else
{
Debug.Log("Data Logged");
}
}
}
I expected the column of intDummy to be 1,2,3,4,.... But the result I get is 1,2,3,14,15,4,16,5,....