Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
You need to go through the server. Giving the client-side code direct access to the database would be a massive security hole, even if you could do it.
What you should do is implement a small server-side script perhaps in PHP or Perl or Python or C#, which outputs just the data you want from the query and use AJAX to process the response.
You need to use a server side language. Otherwise that would be a huge security hole. Anyone could access this database and send arbitrary SQL queries to it.
In theory, it should be possible using the newer features like web sockets, etc. But you shouldn’t do it, considering you’d have to make your credentials public. Create a server side wrapper/negotiator script in whatever available language you’d like to use and call that one. You can as well use it to validate inputs (e.g. filter too absurd highscores or impossible values; depending on what you’re doing).