27
Tutorial 10 by Sam Tutorial 10 by Sam ine1020 Introduction to Internet En ine1020 Introduction to Internet En gineering gineering 1 Database Database & Server-side & Server-side Scripting Scripting Tutorial 10 Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Embed Size (px)

Citation preview

Page 1: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by SamTutorial 10 by Sam ine1020 Introduction to Internet Engineeringine1020 Introduction to Internet Engineering 11

Database Database & Server-side & Server-side

ScriptingScripting

Tutorial 10Tutorial 10

Page 2: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 2

Creating DatabaseCreating Database

►Microsoft Access ExampleMicrosoft Access Example Create a blank databaseCreate a blank database Create a table in databaseCreate a table in database

Page 3: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 3

Creating DatabaseCreating Database

►Setting attributeSetting attribute

Page 4: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 4

Creating DatabaseCreating Database

► Setting primary keySetting primary key

Page 5: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 5

Query DatabaseQuery Database

Page 6: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 6

Query Database - Design Query Database - Design View View

Page 7: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 7

Query Database – Design Query Database – Design ViewView

Page 8: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 8

Query Database – SQLQuery Database – SQL

Page 9: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 9

Database AccessDatabase Access

►Microsoft Universal Data Access (UDA)Microsoft Universal Data Access (UDA) Easy to use programming interfaceEasy to use programming interface Access for relational & non-relational Access for relational & non-relational

databasedatabase Application or Browser

ADO

ODBC

OLE DB

Relational data sources

Non-relational data sources

Mainframe/legacy data

Page 10: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 10

Database AccessDatabase Access

►OLE DB (Object Linking and Ebedding DB)OLE DB (Object Linking and Ebedding DB) Open specificationOpen specification Core architectureCore architecture

Application or Browser

ADO

ODBC

OLE DB

Relational data sources

Non-relational data sources

Mainframe/legacy data

Page 11: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 11

Database AccessDatabase Access

►ODBC (Open Database Connectivity)ODBC (Open Database Connectivity) Access data from a variety of DBMS Access data from a variety of DBMS

through a single interfacethrough a single interfaceApplication or

BrowserADO

ODBC

OLE DB

Relational data sources

Non-relational data sources

Mainframe/legacy data

Page 12: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 12

Database AccessDatabase Access

►ADO (ActiveX Data Objects)ADO (ActiveX Data Objects) Ease to use, high performance, low Ease to use, high performance, low

memory overheadmemory overheadApplication or

BrowserADO

ODBC

OLE DB

Relational data sources

Non-relational data sources

Mainframe/legacy data

Page 13: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 13

Registering a DatabaseRegistering a Database► Specific instructions for Windows Specific instructions for Windows

98/2000/XP:98/2000/XP: double-click the double-click the ODBC Data SourcesODBC Data Sources (32 bit) (32 bit) icon in the icon in the

Windows Control PanelWindows Control Panel to display the to display the ODBC Data Source ODBC Data Source AdministratorAdministrator dialog. dialog. - Click the System DSN tab to

view a list of all systems DSNs.

- Select the name to the right of Microsoft Access Driver (*.mdb) from the list.

Page 14: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 14

Registering a DatabaseRegistering a Database Click Click Add…Add… to display the to display the Create New Data Create New Data

SourceSource dialog. Select dialog. Select Microsoft Access Microsoft Access DriverDriver (*.mdb) (*.mdb) and click and click FinishFinish to display the to display the ODBC Microsoft Access SetupODBC Microsoft Access Setup dialog. dialog.

Page 15: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 15

Registering a DatabaseRegistering a Database Enter the Enter the Data Source NameData Source Name and and DescriptionDescription

field. Click the field. Click the Select…Select… button to display the button to display the Select DatabaseSelect Database dialog. Select the database dialog. Select the database that you want. Click that you want. Click OKOK to close this dialog. to close this dialog.

Page 16: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 16

Registering a DatabaseRegistering a Database

Page 17: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 17

Registering a DatabaseRegistering a Database

The Banking DSN is now listed. The Banking DSN is now listed.

Page 18: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 18

Active Server Pages (ASP)Active Server Pages (ASP)

► Server-side scriptingServer-side scripting ASP file contains HTML and scripting codeASP file contains HTML and scripting code VBScript de facto language for ASP scriptingVBScript de facto language for ASP scripting

►Other languages can be usedOther languages can be used JavaScriptJavaScript

.asp.asp file extension file extension Send dynamic Web contentSend dynamic Web content

►HTMLHTML►DHTMLDHTML►ActiveX controlsActiveX controls►Client-side scriptsClient-side scripts► Java appletsJava applets

Page 19: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 19

Active Server Pages (ASP)Active Server Pages (ASP)► ASP requiresASP requires

Web serverWeb server►Personal Web Server (PWS) Personal Web Server (PWS) ► Internet Information Server (IIS) Internet Information Server (IIS)

► How ASP works ? How ASP works ? Client sends requestClient sends request

►Server receives request and directs it to ASPServer receives request and directs it to ASP►ASP processes, then returns result to clientASP processes, then returns result to client

Server processes ASP fileServer processes ASP file►Parsed (top to bottom) by ActiveX component Parsed (top to bottom) by ActiveX component asp.dllasp.dll

►Parsed each time requestedParsed each time requested►Web server must support ASP by providing Web server must support ASP by providing

component such as component such as asp.dllasp.dll

Page 20: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 20

Active Server Pages (ASP)Active Server Pages (ASP)

► ASP has several built-in objectsASP has several built-in objects RequestRequest object object

►Access information passed by HTTP Access information passed by HTTP GETGET or or POSTPOST►Used to access cookiesUsed to access cookies

ResponseResponse object object►Sends information such as HTML or text to clientSends information such as HTML or text to client

ServerServer object object►Provides access to server methods and propertiesProvides access to server methods and properties►Provides method Provides method CreateObjectCreateObject

Used to instantiate other objectsUsed to instantiate other objects

Page 21: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 21

Active Server Pages (ASP)Active Server Pages (ASP)

► Scripting delimitersScripting delimiters <%<% and and %>%> Indicate code is to be executed on server, Indicate code is to be executed on server,

not clientnot client

►@LANGUAGE@LANGUAGE Specify scripting language (default VBScript)Specify scripting language (default VBScript) <% @LANGUAGE = “VBScript” %><% @LANGUAGE = “VBScript” %>

► Each time page refreshed, server loads Each time page refreshed, server loads and interprets ASPand interprets ASP

Page 22: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 22

ASP/ADOASP/ADO

Data.html

<HTML><HEAD><TITLE>Sample Database Query</TITLE></HEAD>

<BASEFONT FACE = "ARIAL,SANS-SERIF" SIZE = 2><FONT SIZE = +2>

<STRONG>Querying an ODBC database.</STRONG></FONT><BR>

<FORM METHOD = "POST" ACTION = "data.asp"><INPUT TYPE = "TEXT" NAME = "QUERY" SIZE = 40

VALUE = "SELECT * FROM Info"><BR><BR><INPUT TYPE = "SUBMIT" VALUE = "Send Query">

</FORM></BODY></HTML>

Page 23: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 23

ASP/ADOASP/ADO

Data.asp<HTML><BODY>The result of querying an ODBC database <% query = Request( "QUERY" )%> <% ' Open a database connection Set connection = Server.CreateObject( "ADODB.Connection" ) connection.Open( "db2" ) ' Open a record set Set recorderset = Server.CreateObject( "ADODB.RecordSet" ) recorderset.ActiveConnection=connection recorderset.Source=query recorderset.Open%> <TABLE BORDER = "1" CELLPADDING = "5" CELLSPACING = "0">

<% ' Iterate through the record set and create a new row ' in the table for each record While Not recorderset.EOF %> <TR><TD><% =recorderset("District") %></TD> <TD><% =recorderset("ID") %></TD> <TD><% =recorderset("Name") %></TD> <TD><% =recorderset("TelNo") %></TD> </TR> <% recorderset.MoveNext() Wend ' Close the record set and the connection recorderset.Close() connection.close() %> </TABLE><BR><BR></BODY></HTML>

Page 24: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 24

ASP / ADOASP / ADO

Page 25: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 25

Dreamweaver MXDreamweaver MX►Database WindowDatabase Window

Page 26: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 26

Dreamweaver MXDreamweaver MX► RecordsetRecordset

Page 27: Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10

Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 27

Dreamweaver MXDreamweaver MX► Server BehaviorsServer Behaviors

Repeat regionsRepeat regions Dynamic textDynamic text