html5 sql

Discussion and feedback on Construct 2

Post » Mon Mar 14, 2011 9:58 am

Does / will construct 2 or html 5 allow sending and receiving data from an sql database?
B
37
S
19
G
18
Posts: 613
Reputation: 10,231

Post » Mon Mar 14, 2011 11:14 am

Good question. The answer is yes depending on your aims.

To a Server

Everything in HTML and Javascript is client side, that means, whoever is playing your game can theoretically view all the source to it. It will be obfuscated as part of the export process which will serve well in certain types of plagiarism, but for storing connections to databases, this is a big no no as anyone that can view the source and extract the database username and password could cause havock on it by executing any command they wanted. This is why there is no native support for database connections in HTML/JS.

To Local

However, HTML5 has introduced Web Storage, which allows you to create a database on the clients machine. More information is available at:

http://openbit.co.uk/?p=135

This will eventually be supported by Construct, but it will probably only be suitable for save games etc. No server interaction.

Resolving the Server Database Issue

Using AJAX requests, you can POST or GET data on a webpage. You will need a webserver with a database on it. Then you can send commands to the page such as "?score=3342" and the page can interpret the data and save it. So the AJAX acts as the middle man between the client and the database, which is a lot safer.
Image Image
Scirra Founder
B
124
S
37
G
25
Posts: 3,945
Reputation: 44,887

Post » Mon Mar 14, 2011 11:24 am

Thanks for the info.

Could an Ajax extension be possibly written then for construct 2 to handle the POST / GET code stuff and simplify the process?
B
37
S
19
G
18
Posts: 613
Reputation: 10,231

Post » Mon Mar 14, 2011 11:30 am

Yes! Jquery is included with exported games, and it has some excellent AJAX wrappers. These will be available in C2 soon hopefully as they open the door on what can be achieved massively.

AJAX also will be able to manage some multiplayer online games as well (turn based and puzzle). HTML5 websockets will be able to handle real time multiplayer games.

When the AJAX plugins are completed I'll write some tutorials on how these can be applied easily. I'll also write some sample server side code in multiple languages to make it easy for people to install.
Image Image
Scirra Founder
B
124
S
37
G
25
Posts: 3,945
Reputation: 44,887

Post » Mon Mar 14, 2011 11:43 am

[quote="Tom":26gcu5ux]
AJAX also will be able to manage some multiplayer online games as well (turn based and puzzle). HTML5 websockets will be able to handle real time multiplayer games.
[/quote:26gcu5ux]

This was indeed the reason why i was asking. At some point in the future i'd like to maybe have ago at making an AstroEmpires type game.

I'm glad there are options available.

Thanks.
B
37
S
19
G
18
Posts: 613
Reputation: 10,231

Post » Thu Sep 08, 2011 3:17 pm

[QUOTE=Tom] Good question.
Everything in HTML and Javascript is client side, that means, whoever is playing your game can theoretically view all the source to it. It will be obfuscated as part of the export process which will serve well in certain types of plagiarism, but for storing connections to databases, this is a big no no as anyone that can view the source and extract the database username and password could cause havock on it by executing any command they wanted. This is why there is no native support for database connections in HTML/JS.
[/QUOTE]

Why not just switch the .html to .php, it would still then run all the html and javascipt code but only process the php requests server side. I'm not a php/mysql expert but I'm fairly sure php code is not visible client side. The only dilemma I foresee would be not being able to include php into the js files.
B
22
S
9
G
3
Posts: 202
Reputation: 3,645

Post » Thu Sep 08, 2011 3:25 pm

Yes, the PHP file can be located anywhere it doesn't have to be the same page the game is located on. But the client still needs to send data to the PHP page, there is always going to be a gap between the client and the server.
Image Image
Scirra Founder
B
124
S
37
G
25
Posts: 3,945
Reputation: 44,887

Post » Thu Sep 08, 2011 3:44 pm

Tom,

You had mentioned earlier that:

[QUOTE=Tom] Yes! Jquery is included with exported games, and it has some excellent AJAX wrappers. These will be available in C2 soon hopefully as they open the door on what can be achieved massively.

AJAX also will be able to manage some multiplayer online games as well (turn based and puzzle). HTML5 websockets will be able to handle real time multiplayer games.

When the AJAX plugins are completed I'll write some tutorials on how these can be applied easily. I'll also write some sample server side code in multiple languages to make it easy for people to install.[/QUOTE]

Do you still plan to write up a quick tutorial on how all of this is done? I plan on developing (don't laugh) an HTML5 rendition of Shadowgate that doesn't kill the user every three seconds. I will need to have, of course, a login page and a way to manage which rooms, events, items etc each individual user has.

While the method of maintaining a database on the user's computer would be simple I'm guessing it wouldn't take much for them to hack the XML or text code in the file. Hence the need for sql database connectivity. I am decent with sql and okay with php, but have almost no knowledge of AJAX.
B
22
S
9
G
3
Posts: 202
Reputation: 3,645

Post » Thu Sep 08, 2011 3:50 pm

Hi DropTank,

I've added an AJAX tutorial on my to do list!

Tom
Image Image
Scirra Founder
B
124
S
37
G
25
Posts: 3,945
Reputation: 44,887

Post » Thu Sep 08, 2011 3:57 pm

Sweet
B
22
S
9
G
3
Posts: 202
Reputation: 3,645

Next

Return to Construct 2 General

Who is online

Users browsing this forum: anty21ro, mystazsea, nimos100 and 11 guests