Click here to Skip to main content
15,899,126 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hiii friends,

Pls Provide me script or guide for connecting php to sqlserver 2012 using javascript. i have tried a code

HTML
<pre lang="xml"><!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Database Connect</title>
<script type="text/javascript">
function loadDB(){

var connection = new ActiveXObject("ADODB.Connection");

var connectionstring="Data Source=(LocalDB)\v11.0;Initial Catalog=C:\\Program Files\\Microsoft SQL Server\\MSSQL11.SQLEXPRESS\\MSSQL\\DATA\\demo;User ID=GAURAV\GAMER's;Password=\"\";Provider=SQLOLEDB";

connection.open(connectionstring);

var rs = new ActiveXObject("ADODB.Recordset");

rs.Open("SELECT demo_name FROM tbl_demo", connection);
rs.MoveFirst();
while(!rs.eof)
{
   document.write(rs.fields(1));
   rs.MoveNext();
}

rs.close();
connection.close();

}
</script>
</head>
<body onload="loadDB()">
<div id="main"></div>
</body>
</html>

HTML




this is not working properly
Posted

1 solution

WOW!
That would be great!!! You're writing C# code and just add a <script></script> block around it and done! Excellent idea, but unfortunately now going to work (ever).

Javascript runs client side and will not allow you to make such connections. HTML is a language designed for presentation purpose. But languages are not (and will never) be able to connect to a database.
 
Share this answer
 
Comments
g@urav123 25-Sep-13 9:31am    
in google many place i found this type of code. but this works in internet explorer only. and i have heard that html5 makes the connection with database.
Eduard Keilholz 25-Sep-13 9:43am    
No, this is not true. The above code will never work in Internet Explorer and HTML5 will not make a database connection. There is, however e new introduction of called the WebDatabase. See an example here:
http://www.html5rocks.com/en/tutorials/webdatabase/todo/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900