Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: nFighter on April 02, 2019, 10:31:26 PM

Title: Work with MySQL
Post by: nFighter on April 02, 2019, 10:31:26 PM
What is the easiest way to deal with MySQL? Let's say I need a simple task like found and delete some files from web hosted database, what should I use? Is there a common solution?
Title: Re: Work with MySQL
Post by: djaydino on April 03, 2019, 01:16:13 AM
Hi.
If you have easy save you can use that :)

here is in info for setting it up :

https://docs.moodkie.com/easy-save-2/guides/saving-and-loading-from-web/
Title: Re: Work with MySQL
Post by: nFighter on April 04, 2019, 01:20:08 PM
Actually, i'm looking exactly for a way to direct read&write MySQL database because of EasySave limitations. With ES I can serialize data and read/write certain files to their database (it's great, love it). But I can't proceed directly with MySQL requests.

For example:
1) I have an EasySave MySQL database over 1.5 GB.
2) I need to find all files with certain mask and delete them.

Solution 1, native ES actions:
a) download the list of all database files to unity array
b) iterate the array searching for mask and delete them one by one.
Last time I run this solution for 2.5 hours!!!

Solution 2, direct request to MySQL:
a) direct mysql request: DELETE FROM table_name [WHERE Clause]
less then a second!

So, I'm looking for a way to run MySQL requests to support my ES based solution.
Title: Re: Work with MySQL
Post by: jeanfabre on April 05, 2019, 02:30:16 AM
Hi,

normally, your MySql databse is hosted on a server that also provides PHP, use PHP to create a REST api to control your database. This is the most documented and easy way out to control a database from apps.

 you can use https://fatfreeframework.com/3.6/home framework to deal with all the boilerplate code to create REST API. The ecosystem browser is using this framework for its operations.


you could use an asset like https://assetstore.unity.com/packages/tools/network/mysql-database-pro-139070 ( never used it, so I don't know if it works well or not). but that asset is what I mentionned above, it requires you to have a php server, and they simply provide the php file for you, and expose a c# script api to work with it.

Bye,

 Jean
Title: Re: Work with MySQL
Post by: jeanfabre on April 05, 2019, 02:34:48 AM
Hi,

 and apparently, mysql has a beta version with a built in rest api... https://scriptingmysql.wordpress.com/2015/01/15/mysql-5-7-labs-and-the-http-plugin-inserting-updating-and-deleting-records-in-mysql-via-http/

Bye,

 Jean
Title: Re: Work with MySQL
Post by: nFighter on April 05, 2019, 01:19:47 PM
Thanks, seems legit! And what is the regular way to communicate with PHP scripts from playmaker?
Title: Re: Work with MySQL
Post by: jeanfabre on April 08, 2019, 02:01:40 AM
Hi,

 a regular www call will do really.
 a php rest api is simply a "website" that doesn't have any frontend, it only returns data in a string format that can be xml or json or anything else really, it can return an image a video ( streaming or not), etc etc.

for example, the PlayMaker ecosystem browser, is doing just that:

 a simple website url like this:

http://www.fabrejean.net/projects/playmaker_ecosystem/search/float?content_type_mask=&repository_mask=U3U4U5&EcosystemVersion=0.6.4&UnityVersion=5.6.6f2&PlayMakerVersion=1.9.0.p13

will return only text.

a concrete hello world would be this link:

http://www.fabrejean.net/projects/playmaker_ecosystem/

 which is done in php and f3 framework like this:

Code: [Select]
$f3->route('GET /',
   function()
   {
      echo 'This is PlayMaker Ecosystem REST API v1.0. to search for Custom Actions, Templates Samples and Packages, use the <a href="https://hutonggames.fogbugz.com/default.asp?W1181" >Unity Ecosystem browser</a>';
    }
);


 Bye,

 Jean