How to connect to a mySQL database in HTML5?

Hi,
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”
});
// …
cnx.close();

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

Hi
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:

2 Likes

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 : http://dreamlo.com/

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…