network.request() and database

Hi there guys!

This is a newbie question because I don’t understand much of this matter.

What I intend to do is, basically, having a MySQL database of my own, in one of my college’s servers, that database will contain a SQL table with information that I need to get into my Corona SDK android app, is that possible to do with Corona / Lua? And if so, how would I do it? Would it be by using the network.request() function, since I would have to access the database via WiFi?

Thanks in advance!

Basically on your web server, you would use a scripting language like PHP to write several scripts that would take either HTTP GET or HTTP POST requests (in PHP key/value pairs are either in the $_GET[] or $_POST[] tables) that represent the API endpoints you need to setup. You would potentially need a login, register, submit data, search data scripts depending on what you do. Your PHP script’s responsibility is to take the input from our network.request() call and manipulate your database with them. Of course you’re responsible for scrubbing the data to make sure it’s safe. The PHP script talks to your MySQL server. Then the script would output data back to your app and in the listener function for network.request() you get an event table and one of the entries is  “event.response” which holds the output from the PHP script.

Most people have PHP output JSON so  you can easily use our json.decode() API Call to turn that web server output into a Lua table.

Then once you have your script, you use network.request() to load the script passing key/value pairs to it either a GET or POST request.

Rob

Thank you, Rob!

Ensure you hash your requests and check the hash using PHP to ensure the request is a valid request from your app and not malicious.

Basically on your web server, you would use a scripting language like PHP to write several scripts that would take either HTTP GET or HTTP POST requests (in PHP key/value pairs are either in the $_GET[] or $_POST[] tables) that represent the API endpoints you need to setup. You would potentially need a login, register, submit data, search data scripts depending on what you do. Your PHP script’s responsibility is to take the input from our network.request() call and manipulate your database with them. Of course you’re responsible for scrubbing the data to make sure it’s safe. The PHP script talks to your MySQL server. Then the script would output data back to your app and in the listener function for network.request() you get an event table and one of the entries is  “event.response” which holds the output from the PHP script.

Most people have PHP output JSON so  you can easily use our json.decode() API Call to turn that web server output into a Lua table.

Then once you have your script, you use network.request() to load the script passing key/value pairs to it either a GET or POST request.

Rob

Thank you, Rob!

Ensure you hash your requests and check the hash using PHP to ensure the request is a valid request from your app and not malicious.