0

I have a project i am working on. It contains html/javascript. I am trying to set a connection from SQL to my html/javascript project. Currently i have a Json datastructure inside my script but i wan't to change this to SQL.

Is this even possible? I can only find tutorials about php + sql

I use this query to get data from my json

$(".een").empty().append(mydata[i].name + '<br> ' + mydata[i].version + '<br> ' + mydata[i].LocalTimeZone + '<br> ' + mydata[i].country);
$(".twee").empty().append(mydata[i].input);
$(".vier").empty().append(mydata[i].properties);

What i have so far

Whenever you click the rectangle it shows data from the Json i want it to show data from a SQL database. Does any 1 know a good tutorial website/video?

Sébastien Renauld
  • 19,203
  • 2
  • 46
  • 66
Script
  • 21
  • 1
  • 7
  • 1
    From what SQL database? One that isn't running inside the browser? But is on a different computer entirely? While technically (maybe) possible, it's ludicrously complicated with horrific security implications. – Quentin Jun 01 '15 at 10:40
  • Duplicate: [How to connect to SQL Server database from JavaScript?](http://stackoverflow.com/questions/857670/how-to-connect-to-sql-server-database-from-javascript) – Yogi Jun 01 '15 at 11:01

2 Answers2

3

Short answer is "you really don't want to do that".

The long answer is a bit more complicated. In order to do this, you will need to find a database store that is fully accessible using HTTP. This isn't exactly easy to find. Your best candidate would be to use ElasticSearch as a datastore and single source of truth, which isn't the best thing since sliced bread (ES suffers from a few issues, including data recovery).

Why just HTTP?

In order for JS to communicate, it needs to do so using XHR or websocket. To my knowledge, not a single datastore enabled any kind of websocket-esque protocol, so you're stuck with XHR. And that rules out MySQL, Mongo, Postgre, Oracle... and leaves only NoSQL solutions.

Okay. ES. What next?

In addition to this, you'll need to put something in front of ES in order to disallow some of the more "dangerous" calls to it.

Assuming you still want to go with this, once it is set up and fully public (alarm bells should be ringing around now), you'll be able to run standard ES queries on it.

Sébastien Renauld
  • 19,203
  • 2
  • 46
  • 66
0

If you're talking about connecting to a database on a server, this is really horrific unless you have server side JS application such as Node. You can't just expose your database to anybody on the web.

Sid Shukla
  • 990
  • 1
  • 8
  • 33