Примеры программ

Листинг 4.12. Файл для доступа к БД MS Access'97.

[ODBC]
DRIVER=Microsoft Access Driver (*.mdb)
UID=admin
UserCommitSync=Yes
Threads=3
SafeTransactions=0
ReadOnly=0
PageTimeout=5
MaxScanRows=8
MaxBufferSize=512
ImplicitCommitSync=Yes
FIL=MS Access
DriverId=281
DefaultDir=C:\Inetpub\scripts\bookcd
DBQ=C:\Inetpub\scripts\bookcd\bakal1.mdb

Сценарий, использующий этот файл, приведен в листинге 4.14.

Листинг 4.13. Файл для доступа к БД MySQL.

[ODBC]
DRIVER=MySQL ODBC 3.51 Driver
UID=gun
STMT=
OPTION=3
PORT=
PASSWORD=
SERVER=inna
DATABASE=test

Листинг 4.14. Сценарий формирования DSN.

<%
Dim sDB, sPath, sDSNFil, sDSN, sScriptDir
'This is the entire DB path 
sDB = "C:\Inetpub\scripts\bookcd\bakal1.mdb"
	' Retrieve the script directory
	sScriptDir = Request.ServerVariables("SCRIPT_NAME")
	sScriptDir = StrReverse(sScriptDir)
	sScriptDir = Mid(sScriptDir, InStr(1, sScriptDir, "/"))
	sScriptDir = StrReverse(sScriptDir)
' Set the virtual Directory
sPath = Server.MapPath(sScriptDir) & "\"
' This is the DSN file Name for Access database
sDSNFil = "Access.dsn" ' This is the resulting DSN string
sDSN="filedsn="&sPath&sDSNFil&";DefaultDir="&sPath&";DBQ="&sPath&sDB&";"
%>

Листинг 4.15. Файл включения.

<%
' ADO constants include file for VBScript
'---- CursorTypeEnum Values ----
Const adOpenForwardOnly = 0
Const adOpenKeyset = 1
Const adOpenDynamic = 2
Const adOpenStatic = 3
%>
<FONT FACE="Verdana, Arial" SIZE=2>
<FORM ACTION="<% =sScript%>" METHOD=GET>
<SELECT NAME=YEAR>
<OPTION VALUE=1998 SELECTED>1998
<OPTION VALUE=1999>1999
<OPTION VALUE=2000>2000
<OPTION VALUE=2001>2001
<OPTION VALUE=2002>2002
</SELECT></FONT>
<P><INPUT TYPE="Image" SRC="images/go.gif" BORDER="0" WIDTH="35" HEIGHT="20"> </P>
</FORM>

Листинг 4.16. Сценарий авторизации посетителя.

<!-- #include file ="dsn.asp" -->
<!-- #include file="adovbs.inc" -->
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>Идентификация пользователя</title></head>
<body BGCOLOR="#CCCCFF" TEXT="#0000FF" LEFTMARGIN="3">
<%
If not isEmpty(Session("userlevel")) then  
   Session("userlevel") = Empty
   Session("userid") = Empty
end if
user = Request.Form.Item("T1")
pswd = Request.Form.Item("T2")
b1 = Request.Form.Item("B1")
If not isEmpty(user) and not isEmpty(pswd) then  
  	Set Rs = Server.CreateObject("ADODB.RecordSet")
	sSQL = "SELECT Users.Pswd, Users.Access_ID, 
	Users.User_ID FROM Users WHERE Users.Login = '"&user&"'"
	Rs.Open sSQL, sDSN
	if not RS.EOF then
     if RS.fields(0).value = pswd then
       Session("userlevel") = RS.fields(1).value
       Session("userid") = RS.fields(2).value
       Response.Redirect("menu.asp")
     end if  
   end if 
   Session("userlevel") = 3
   Response.Redirect("menu.asp")
end if
%>
<form method="POST" action="enter.asp">
<center>
<table border="0" width="50%" cellspacing="1" cellpadding="4">
<tr><td width="100%" colspan="2" bgcolor="#000080">
<b><font size="4">Идентификация пользователя </font> </b></td> </tr>
<tr><td width="50%" align="right">Имя:</td>
<td width="50%"><input type="text" name="T1" size="20"></td>
</tr>
<tr><td width="50%" align="right">Пароль:</td>
<td width="50%"><input type="password" name="T2" size="20"></td>
</tr>
<tr><td width="100%" align="right" colspan="2">
<center><input type="submit" value="Войти" name="B1" ></td>
</tr>
</table></center>
</form></body></html>

Листинг 4.17. Сценарий доступа к БД MySQL.

<%@ LANGUAGE="VBScript"%>
<!-- #include file ="e14a.asp" -->
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" content="text/html; charset=windows-1251"> 
<TITLE>Using MySQL</TITLE></HEAD><BODY>
<%
Dim objRecordset
Set objRecordset = Server.CreateObject("ADODB.Recordset")
' Устанавливаем подсоединение и выполняем запрос
objRecordset.Open "SELECT name FROM people", sDSN
%><!-- Строим список SELECT по набору данных -->
<SELECT SIZE=3>
<% Do While Not ObjRecordset.EOF %>
<!-- Создаем очередной элемент списка --> 
<OPTION><%=objRecordset("name")%></OPTION>
<% objRecordset.MoveNext 
Loop %> 
</SELECT></BODY></HTML>
Hosted by uCoz