A package to communicate from Unity to a mysql database using PHP
namespace JelleVer.DatabaseTools
This can be imported as a UnityPackage in any existing Unity project through the Package manager with the Git url.
You can find the full documentation here: jellevermandere.github.io/DatabaseTools
The connection is made through the DB_Connect
script.
Fill in the correct url's and table name in the inspector.
There are callbacks in the form of UnityEvents when a request is completed
Data can be send to the database using:
public void TryUploadData(string username, Object data){}
public void TryUploadData(string username, string data){}
Where the username is used to identify the player and the data can be anything you want.
If the data is passed as an object make sure it's [System.Serializable]
, it will get serialized to JSON before being send.
The data can be downloaded using:
public void TryDownloadData(){}
It will return all the entries in the database as an array of:
public class UserData
{
public string username = "";
public string data = "";
}
The data is received as a UserDataArray
as a wrapper class, but the UnityEvent passes a regular UserData[]
You will need a mysql database and a server that supports PHP.
Fill in the database credentials in dbh.inc.php
in the ServerFiles
folder:
$dbServername = "";//Database server name;
$dbUsername = "";//Database username;
$dbPassword = "";//Database password;
$dbName = "";//Database name;
Put the whole folder on your server. and fill in the link in the DB_Connect
in Unity.
The code in this project is licensed under MIT license.