html前端怎么连接数据库(html页面和链接数据库)
大家好,html前端怎么连接数据库相信很多的网友都不是很明白,包括html页面和链接数据库也是一样,不过没有关系,接下来就来为大家分享关于html前端怎么连接数据库和html页面和链接数据库的一些知识点,大家可以关注收藏,免得下次来找不到哦,下面我们开始吧!
web登陆页面,怎么连接数据库
建一个web.config页面里面就是配数据库连接的。。给你一段代码你看看:
<configuration>
<appSettings/>
<connectionStrings>
<!--链接SQL Server数据库的链接字符串-->
<add name="Mispersonalconn" connectionString="data Source=(local);database=DB_Mispersonal;uid=sa;pwd=sa" providerName="System.Data.SqlClient"></add>
</connectionStrings>
<system.web>
<!--
设置 compilation debug="true"将调试符号插入
已编译的页面中。但由于这会
影响性能,因此只在开发过程中将此值
设置为 true。
-->
<compilation debug="true"/>
<!--
通过<authentication>节可以配置 ASP.NET使用的
安全身份验证模式,
以标识传入的用户。
-->
<authentication mode="Windows"/>
<!--
如果在执行请求的过程中出现未处理的错误,
则通过<customErrors>节可以配置相应的处理步骤。具体说来,
开发人员通过该节可以配置
要显示的 html错误页
以代替错误堆栈跟踪。
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm"/>
<error statusCode="404" redirect="FileNotFound.htm"/>
</customErrors>
-->
<!--globalization fileEncoding="UTF-8" requestEncoding="UTF-8" responseEncoding="UTF-8"/-->
<globalization fileEncoding="gb2312" requestEncoding="...
HTML5怎么连接数据库
HTML5连接数据库分为以下几步:
预备知识:Web SQL Database,Html5环境下可以用Js执行CRUD的Web数据库组件。
核心方法如下:
1、openDatabase:这个方法使用现有数据库或创建新数据库创建数据库对象。
2、transaction:这个方法允许我们根据情况控制事务提交或回滚。
3、executeSql:这个方法用于执行真实的SQL查询。
第一步:打开连接并创建数据库
var dataBase= openDatabase("student","1.0","student", 1024* 1024, function(){});
if(!dataBase){
alert("数据库创建失败!");
} else{
alert("数据库创建成功!");
}
第二步:创建数据表
this.createTable=function(){
dataBase.transaction( function(tx){
tx.executeSql(
"create table if not exists stu(id REAL UNIQUE, name TEXT)",
[],
function(tx,result){ alert('创建stu表成功');},
function(tx, error){ alert('创建stu表失败:'+ error.message);
});
});
}
第三步:执行增删改查
添加数据:
this.insert= function(){
dataBase.transaction(function(tx){
tx.executeSql(
"insert into stu(id, name) values(?,?)",
[id,'徐明祥'],
function(){ alert('添加数据成功');},
function(tx, error){ alert('添加数据失败:'+ error.message);
});
});
网站制作 静态的HTML文件已经做好了,怎么连接数据库
access数据库一般用ASP,下面是示例代码:
asp连接access数据库应用下面代码
<%
set conn=Server.CreateObject("ADODB.Connection")
DBPath= Server.MapPath("board.mdb")'Server.MapPath("board.mdb")获得数据库文件board.mdb的绝对路径
conn.Open"provider=microsoft.jet.oledb.4.0;data source="&dbpath
%>
首先在board.mdb数据库里建立一张数据表board(id,title,content,subtime)个字段数据类型自己思考,环境都建好了,下面我们就开始程序设计,无论网页还是程序我建议用dw来做吧,我就是用它的
本例中涉及到的文件有
conn.asp数据库链接文件
send.asp,发表留言界面页
sendok.asp,留言录库操作程序文件
board.asp留言读库显示页面
文件的内容附件里有源文件大家可以下载察看
首先介绍asp一个很有效的特性就是服务器端包含
<!--#i nclude file="conn.asp"-->
其中conn.asp就是被包含的文件,此包含可以出现在文件的任意位置
被包含的文件内容将完全被解释成包含文件的内容,,重复的代码也会大大降低。
conn.asp内容
<%
set conn=Server.CreateObject("ADODB.Connection")
DBPath= Server.MapPath("board.mdb")
conn.Open"provider=microsoft.jet.oledb.4.0;data source="&dbpath
%>
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
send.asp内容
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; ch***t=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
.style1{font-size: 18px}
-->
</style>
</head>
<body>
<table width="700" border="0" align="center">
<form name="form1" method="post" action="sendok.asp">
<tr>
<td><div align="center" class="style1">发布留言</div></td>
</tr>
<tr>
<td align="center">
<input name="title" type="text" size="50"></td>
</tr>
<tr>
<td align="center">内容:
<textarea name="content" cols="50"></textarea></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="提交"></td>
</tr>
</form>
</table>
</body>
</html>
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
sendok.asp内容
<!--#i nclude file="conn.asp"-->
<%
title=request.form("title")
content=request.form("content")
subtime=now()
conn.execute("insert into board(title,content,subtime) values('"&title&"','"&content&"','"&subtime&"')")
%>
<script>
alert("留言成功!");
location.rel="external nofollow" href="/board.asp";
</script>
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
board.asp内容
<!--#i nclude file="conn.asp"-->
<style type="text/css">
<!--
.style2{
font-size: 16px;
font-weight: bold;
}
-->
</style>
<table width="300" border="0" align="center">
<tr>
<td align="center"><span class="style2">留言板查看</span></td>
</tr>
</table>
<br>
<br>
<table width="200" border="0" align="center">
<tr>
<td align="center"><a rel="external nofollow" href="/send.asp">发表留言</a></td>
</tr>
</table>
<br>
<br>
<%
set rs=conn.execute("select* from board order by id desc")
do while not rs.eof
%>
<table width="600" border="0" align="center" cellspacing="1" bgcolor="#999999">
<tr bgcolor="#FFFFFF">
<td width="447"><%=rs("title")%></td>
<td width="146"><%=rs("subtime")%></td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="2"><%=rs("content")%></td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="2"></td>
</tr>
</table>
<%
rs.movenext
loop
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
关于html前端怎么连接数据库的内容到此结束,希望对大家有所帮助。