I have created a word game on HTML5 canvas. For now it fetches the words from the word array in a javascript file. But I have created a database table in MySQL containing more words. How can I conect my HTML file to it. The answer may be simple but I donot know JSP or its equivalents so it is causing me problems.
Asked
Active
Viewed 516 times
2 Answers
3
JavaScript cannot directly connect to MySql, You need a server side database, I recommend you to learn FireBase, and upload your wordlist to there. Why FireBase? Because:
- it is simple,
- Most of the times it's free.
- You don't need a server, or server side programming
You can use SQLite with JavaScript, and download the file using AJAX, but it's not recommended. (Why to download all the list of the words to every client)

Aminadav Glickshtein
- 23,232
- 12
- 77
- 117
-
Actually the database is already there in MySQL database and it is huge. I made the game and it needs to fetch the words already there in the table. That's the job :( – user3722844 Jun 09 '14 at 16:29
-
So try to import it to FireBase, you must have a server – Aminadav Glickshtein Jun 09 '14 at 16:32
-
1JavaScript is a client side scripting language you can't access server side data with a client side language. You have to choose another db technology that can be accessed with JavaScript. – lokeshpahal Jun 09 '14 at 16:40
1
I suggest using a server side language like PHP. Why you may ask?
- PHP supports MySql PHP MySql Manual
- You can use most if not all of your html5 markup
- If your word game is computationally expensive, PHP can do some work on the server-side, thus improving the user experience
- PHP outputs Html
Downloading large lists of words to every user of the game will use a lot of server bandwidth, which may make the user experience slow.
Accessing databases from javascript is possible (ActiveXObject example) but its frowned upon for security reasons.