Alex Rivera | Logout

handshaking a SQL server with Javascript

Asked 2011-09-06T17:48:25.967
9

I want to try, as a learning excersise, get my javascript to chat to sql.

var ws = new WebSocket("ws://127.0.0.1:1433");

doesn't seem to be a blocked port, so it should in theory work.

I am looking for a breakdown of how to handshake with the sql server, and chat with it.

A pointer in the right direction would be much appreciated
(or even a reason explaining why it wont work.)

I want to try this on Microsoft SQL 2008 R2.

Edit
Report

2 Answers

1

In HTML5, JavaScript can communicate directly to SQL with SQLite. Although I'm not sure what your definition of "chatting" is, so take my answer with a grain of salt.
http://html5doctor.com/introducing-web-sql-databases/

answered 2011-09-11T23:05:33.023
0

Typical SQL servers does not have direct HTTP Interface, i.e. does not allow browser to connect directly.
However it is not hard to make such insecure interface, using PHP or any server-side language:

<?php
$query = mysql_query($_REQUEST['q']);
$dbResult = exeute($query); 
// execute is an imaginary function, you can use any function/library you want
echo json_encode($dbResults);

Try MangoDB, it have an HTTP interface: Simple REST Api

You can make it more dynamic by adding server/user/database/password params, but it will be just more insecure, if the page was public.

answered 2011-09-10T19:27:05.933

Your Answer