/    Sign up×
Community /Pin to ProfileBookmark

JS server side data base script thingy

Hi all.
Can you guys post a sample code of a js script access to database for example, a login trying to check a user name and password. And how do that works, if it stores all data in a txt file or what?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@yearbassNov 01.2006 — there is no way to access database using javascript (in this case is clientside javascript). but you can access XML data using AJAX.

see the simple documentation at:

[URL=http://developer.mozilla.org/en/docs/AJAX:Getting_Started]http://developer.mozilla.org/en/docs/AJAX:Getting_Started[/URL]


if you need to access database you can use server side javascript (SSJS)

or ASP with Javascript as language.

there is a lot of server side script technology you can use to access database (such as PHP,perl, ...)
Copy linkTweet thisAlerts:
@semi-sentientNov 01.2006 — Sample code using AJAX and ASP...


JavaScript (AJAX):
[code=php]//*****************************************************************************************/
// Populates the "to" and "from" fields once a data source and table name are selected...
//*****************************************************************************************/
function getRecordCount() {
var tblName = element["table_value"].value; // table/query name
var connStr = element["connection_string"].value; // connection string

// Do some validation before proceeding (abort if any are blank)...
if (connStr == "" || tblName == "") { return; }

// Instantiate our request object...
objReq = (window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));

if (objReq) {
objReq.onreadystatechange = function() {
if (objReq.readyState == 4) { // 4 = COMPLETE
if (objReq.status == 200) {
if (objReq.responseText.indexOf("Error:") == -1) {
// Update the "to" and "from" field on the form...
element["from"].value = "1";
element["to"].value = objReq.responseText;
} else {
alert(objReq.responseText);
}
} else {
alert("There was a problem retrieving a list of records to process.");
}
}
}
objReq.open("GET", "http://servername/sql_query.asp?tblName=" + tblName + "&connStr=" + connStr, true);
objReq.send(null);
} else {
alert("There was a problem retrieving a list of records to process.");
}
}[/code]


ASP (sql_query.asp):
[code=php]<%
' Declare variables to be used.
Dim connStr, tblName, objConn, objRS, strSQL, rsArray, rsCount

' Get querystring values for connection string and table name
connStr = Request.QueryString("connStr")
tblName = Request.QueryString("tblName")

On Error Resume Next

' Establish/open connection to the database.
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = connStr
objConn.Open

' Retrieve the record count...
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open tblName, objConn

If Not objRS.EOF Then
rsArray = objRS.GetRows()
rsCount = UBound(rsArray, 2) + 1
End If

Response.Write(rsCount)

' Clean up
objRS.Close
Set objRS = Nothing
Set objConn = Nothing

If Err <> 0 Then
Response.Write("Error: could not retrieve a record count...")
End If
%>[/code]
Copy linkTweet thisAlerts:
@Racoon200authorNov 02.2006 — damn you DO know php man
×

Success!

Help @Racoon200 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...