• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Android How to connect to Mysql database

3jgamesdev

Member
Hi guys good day,

I keep searching about this but still i dont understand this part, i have uploaded my database online using free web host for now, i want to get those information and use it for my game, but i dont know how im going to do it, im using php on it hope you can help me step by step, i have search about getting the api, but how im going to take the information from my database(mysql)

im trying to use the http_get and http_post(i dont know ifwhat i did is correct), but im not getting any information, i was trying and follow the youtube tutorials but it seems it was little different

thanks
 
Last edited:
W

Walky

Guest
I haven't used any online functionality of GMS but I did work a few years with PHP so maybe I can help.

By looking at the documentation, it seems this may be the information you're looking for:
https://docs.yoyogames.com/source/dadiospice/001_advanced use/more about async events/http.html

To generate a response from your web server you'll need to make a PHP file that receives the arguments from GMS, queries the database and then generates an output that can be picked up by GMS.

Depending on your needs, you can for example send an argument that specifies if you want to update the database or get information from it (or you can use different PHP files).

Note: Be sure to always escape the arguments your PHP file receives before using them in a query! (https://www.w3schools.com/php/func_mysqli_real_escape_string.asp)
 

FrostyCat

Redemption Seeker
Are those still pretty relevant? Definitely going to save them as a reference.
It's still relevant to a basic degree. I would recommend using a framework for new PHP projects, and save raw PHP only for legacy maintenance.
Note: Be sure to always escape the arguments your PHP file receives before using them in a query! (https://www.w3schools.com/php/func_mysqli_real_escape_string.asp)
mysqli_real_escape_string() has been supplanted by PDO prepared statements on the most part in PHP. The latter is stronger against injection attacks and do not require manual escaping. Prepared statements are now the industry standard, regardless of language or framework.
 
W

Walky

Guest
That's correct, I should have mentioned that (I didn't get a chance to use them in my previous job so I often forget about them).
 

3jgamesdev

Member
can you guys help me step by step procedure about it, i try to follow this but it seems still i didnt get it, I think i know now where to start but still doesnt sure if what i was working is correct

sorry guys im not good using php,i just know the basics

really thanks for helping me out guys
 
Last edited:

FrostyCat

Redemption Seeker
What's not to get? Take the PHP code, replace the MySQL credentials, and save it as a .php file in your web root. All web hosts have specific instructions on what the MySQL credentials and web root directory are. Then call http_get(), http_post_string() or http_request() from GML, replace the URL with the one corresponding to the .php file you saved earlier in your account, and process the response in the HTTP event. If you use JSON on both ends like a sane person should and your host doesn't mess with the response, none of this should take you more than an hour.
 
H

Homunculus

Guest
Remember that you can access your php pages directly from a browser (at least for those requests that simply return the database data). There’s no need to rush and code everything in a single shot. Prepare a php page, open it in a browser to verify that your data is there, and then start integrating in gm using http functions.
 
Top