How to use MySQL in Solar2D

Hello. I want to create a ranking (MySQL table) for people who play my game.

How I can make it? (I can use SQLite databases but I have no idea how to use MySQL in Solar2D).

I need to:

  1. save information to table repetitively
  2. get this table in one scene

Or maybe there is another better way to do this. Because I need only one table (ID, name, cash).

You’ll need to have the database hosted somewhere and look into backend stuff to write to it and read from it, probably PHP, combined with network requests.

Or you could use the gameNetwork apis for leaderboards. -https://docs.coronalabs.com/api/library/gameNetwork/index.html

1 Like

I have never use PHP… :confused: But I will try.

I think I need to upload php file to my website and in lua file I need to use network.request(), I’m right?

Yes, use PHP on the server and echo the response back. In lua issue a network.request and then convert the response to a table and process that. You can Google the PHP stuff - my advice is to use PDO (if your host supports it).

1 Like

I have spent significant time doing apps on Solar2D previously corona to talk to database

you have the following options:

  • you can use SQLLite locally which is not useful in your case, because you want the database to be read by anyone

  • you can use relational database like MSSQL, ORACLE, MYSQL, or any other relational database, and this option requires designing a webservice to be placed on a server that talks to the database and your app, because most SDKs cannot talk directly to relational database like other languages do, like for example PHP, .NET, JAVA … etc. because database engines require something called database client for each programming language to be able to talk to that database … and this is something that does not exist here… so simply create a database, create a webservice that talks to database, and finally create an app that talks to webservice asking for info from the database, or submitting info to the database

  • Last but not least, you can have something called NoSQL, like google firestore, MongoDB … which eliminates the need for a webservice, meaning that you can directly write and read from database through a few lines of code

each point of the 3 above can be as complicated as one can imagine or vise versa … depends on your app

1 Like

Thank you guys, your answers really helped me! :slightly_smiling_face:

I’ve thought about using an external db to keep track of high scores for an upcoming game but have thus far decided against it.

The biggest reason: If you allow people to create their own names, you are going to get a bit more mature rated language used (to put it diplomatically) and if your game is aimed at both kids and adults, you may want to put in code that detects different variations of this. language and scrubs them from the high scores list.

After I thought about it a bit, I felt it was too much trouble. I wonder if there are still 3rd parties that do this stuff – back in the early days of mobile, there were a few third party high score providers.