Online databases?

How do I communicate with an online database? I see there’s a sqlite plugin you can activate in engine but no info on that?

Hey there @fael097! You could use a couple of methods.

If you’re using SQLite you could use the SQLite plugin but there isn’t documentation so you’d have to check the source (visible if you setup your Unreal Engine Github Access):

https://github.com/EpicGames/UnrealEngine/tree/b70f31f6645d764bcb55829228918a6e3b571e0b/Engine/Source/Runtime/SQLiteSupport

In my experience, we used a MySQL database setup to take HTTPS requests and use a mix of the built in Unreal HTTP request system or the VaREST plugin to make API calls to the server with the DB.

https://www.unrealengine.com/marketplace/en-US/product/varest-plugin

Another alternative is to use one of the many paid solutions on the Unreal Engine marketplace.

https://www.unrealengine.com/marketplace/en-US/assets?count=20&keywords=MySQL&sortBy=relevancy&sortDir=DESC&start=0

Disclaimer: One or more of these links are unaffiliated with Epic Games. Epic Games is not liable for anything that may occur outside of this Unreal Engine domain. Please exercise your best judgment when following links outside of the forums.

1 Like

I agree w/@SupportiveEntity

You do not want a server or client having direct DB connection credentials. Your asking to be hacked and your DB destroyed.

SELECT name FROM sqlite_schema WHERE type ='table' AND name NOT LIKE 'sqlite_%';
DROP TABLE IF EXISTS SomeTable;

You want a secure middleman service (RESTful API) the server can send requests to and receive json responses from.

Security is key here.

2 Likes

That sounds perfect, I already have a MySQL database basic setup and it’s what I was hoping to use, however I didn’t want to use third party paid plugins and was looking for a free alternative. I was also concerned about security, so this sounds ideal.

Could you show a simple example on how to securely connect to a database, retrieve data from it, and write into it? I use blueprints and I don’t know much about the specifics of database communication.

thanks!

Could you show a simple example on how to securely connect to a database, retrieve data from it, and write into it? I use blueprints and I don’t know much about the specifics of database communication.

There are no “simple examples”. This is a complex task.

You need a web server in which to develop and deploy a REST API. The API itself would have connectivity with the DB. You’d develop specific api queries the game server (GS) would request with an argument and parameters. The API would process the request and return a json array.

The GS would then parse the json array into useful data.

I recommend Php/MySQL as there’s tons of documentation/support/tutorials. Php is also easier to learn and 99% of all webhosting services offer it. I will note that once you get a lot of servers/users hitting the api (# requests per minute) you’ll need to transition to a pure C++ service (C++ instead of php).


All Web based API’s (uses WAN) are structured/developed like a typical website. You enter a url and the page executes the request and responds with data a browser would display.

e.g. https://mydomain.com/myapi/

Private API’s are typically token/key based. Meaning the user must have permissions to access the data/action requested. Keys are provided and managed by the api. Each token represents a specific user (e.g. GS1, GS2, GS3 etc).

All requests to the API for data, say player stats, requires the key/token as an argument parameter.
https://mydomain.com/myapi/players/?token=###&player=###&arg=###
Argument Params:

Token = GH!fV45949gjcm349itg9 // 256bit hashed token
Player = 123123534 // players id
Arg = stats 

The Argument (arg) would tell the api what specific data you want.
e.g. Stats, Cosmetics, GameSave, GameSettings, Keyboard binds etc

Most API’s utilize CuRL for communication between user and service.
Here’s an example from an old project.

// ARGS: TRN_API_KEY, PLATFORM, SERVERID
$url = "https://battlefieldtracker.com/bf1/api/quick-server-info?platform=".$args['platform']."&id=".$args['serverid'];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('TRN-Api-Key:'. TRN_API_KEY));
$response = curl_exec($ch);
$status = curl_getinfo($ch);
curl_close($ch);

The response would be reformatted to specific needs.

$r = json_decode($response, true); 
$result['server'] = array(
'name' => $r['serverInfo']['name'],
'slots' => $r['slots']['Soldier']['current']."/".$r['slots']['Soldier']['max'],
'mode' => $r['activityInfo']['currentMode'],
'map_name' => $r['activityInfo']['currentMap'],
'mapimg' => NoLeech('map', $r['activityInfo']['mapImageUrl']),
'description' => $r['serverInfo']['description'],
'que' => $r['slots']['Queue']['current']."/".$r['slots']['Queue']['max'],
'spectator' => $r['slots']['Spectator']['current']."/".$r['slots']['Spectator']['max']
);

A good start would be to look into PHP REST API Frameworks like Comet, Laravel, Leaf, Lumen (lightweight laravel) etc. Definitely hit up StackOverflow.

1 Like

Once you setup REST, the API, and connect it to the DB, VAREST (the free plugin I mentioned earlier) can handle the communications. If you would prefer not to use any third party, you can check out how they did the actual communication inside the plugin’s source and run your own custom:

Though it looks like the repo is behind the plugin release.

Maybe this will help.

1 Like