How to connect to a mySQL database in HTML5?

Haxe seem to offer some functions to connect to a database, but I can’t get it work…

var cnx = neko.db.Mysql.connect({
host : “localhost”,
port : 3306,
user : “root”,
pass : “”,
socket : null,
database : “MyBase”
// …

I found this example on this page :
I believe I must change the “neko.db.Mysql” with something else, but I can’t find what to use…

Looking at the code, you can see that these are functions of the Neko platform, not the functions of the Haxe language. As far as I know, this platform is not in Armory3D

This looks like it could help you:


Thanks @timodriaan, it seems very interesting, but I don’t know how to use it…
Where do I need to put this library ?

I have no idea, I never used that library and just googled if there was something that looks like it might bring SQL support to Haxe. Try putting it into the Libraries folder of your project just like any other libraries.

Well, I managed to use the library, but it does not work for js, as it use sys.db.Mysql.
So the console tells me :

You cannot access the sys package while targeting js (for sys.db.Mysql)

Too bad…
Any other solution ? I’m still looking for a way to make a leaderboard…

A “server” layer is needed to work with the database: php, js …
The game will communicate with the server via url.
P.S. Maybe the code from here will help to access the url:

1 Like

Yes this would work, I also found recently a way to send HTTP requests with haxe. I could even use this nice service :

But the bad new is that the URL is transmitted and clearly visible with the developer tools of the browser.

It’s too easy to cheat with this method, not good for a leaderboard…

Packing (json), serialization and encryption.
As a result, the sending will be only an encrypted string, which will be visible, but changing it correctly is already difficult.

More option:

1 Like

Thanks @E1e5en I will look at that. I don’t really know about it, but I’ll learn…

For what it’s worth, I don’t recommend trying to connect directly to a MySQL database from the client side of anything. Especially if you plan to have a lot of simultaneous users. It is almost always the best way to set up a traditional client/server architecture and to expect the server to make SQL requests as-needed to service its clients’ needs. The SQL server therefore has a moderate number of connections to deal with – one for each application-server instance, not one for each client they are communicating with. The application server is also thus in a good position to handle issues like concurrency that an SQL server is just not the best one to handle directly.