Question by
AdrellaDev · Sep 25, 2019 at 04:11 AM ·
unity 5databasephpsql
PHP & SQL on Android
Hi there, I'm having a lot of trouble getting SQL data to my Android app. In the editor it works just fine but the build on my device is not getting any data. My timer isn't even showing up which makes me think the code is hitting an error somewhere but I can't see because as I said, it works great in the editor. Here's my C# code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
public class DatabaseData : MonoBehaviour
{
string data = "https://mywebsite.com/mydata.php";
public Text statusText;
string[] categories;
public Text date;
public Text incomingData;
private void Start()
{
StartCoroutine(GetData());
}
IEnumerator DataTimer()
{
yield return new WaitForSeconds(5.0f);
StartCoroutine(GetData());
}
IEnumerator GetData()
{
//Update date and time to show when last call to server was
date.text = System.DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
statusText.text = "Loading Data";
UnityWebRequest hs_get = UnityWebRequest.Get(data);
yield return hs_get.SendWebRequest();
if (hs_get.error != null)
{
statusText.text = hs_get.error;
}
else
{
statusText.text = hs_get.downloadHandler.text;
string fullData = statusText.text;
string[] splitString = fullData.Split(" "[0]);
int[] values = new int[splitString.Length - 1];
string[] splitArray = fullData.Split(char.Parse(";"));
incomingData.text = splitArray[0];
StartCoroutine(DataTimer());
}
}
Like I said, everything works fine in the editor but no luck on Android. I have copied over .dll files and the sql database is hosted online with Unity only pinging the php files so there shouldn't be any issues with ports or anything. I'm just at a complete loss and could use some advice. Thanks!
Comment