Download presentation
Presentation is loading. Please wait.
1
Connecting a Database to a Web Application Professor Stephen K. Kwan
2
Motivation Saving submitted data into a database for later processing and analysis (e.g., feedback form, customer registration, etc.)Saving submitted data into a database for later processing and analysis (e.g., feedback form, customer registration, etc.) Serving data from a database based on some search criteria and/or specified category (e.g., electronic products catalog, online library catalog, etc.)Serving data from a database based on some search criteria and/or specified category (e.g., electronic products catalog, online library catalog, etc.)
3
Ingredients HTTP server - have access and storage privilege in a directory with executable permissionHTTP server - have access and storage privilege in a directory with executable permission A Database for the applicationA Database for the application ODBC - have ability to define a Data Set Name (DSN) on server pointing to target databaseODBC - have ability to define a Data Set Name (DSN) on server pointing to target database HTML form for submitting query or dataHTML form for submitting query or data ASP programs with desired functionalityASP programs with desired functionality
4
HTTP Server: Microsoft NT or 2000 Server with IIS (Internet Information Services), HTTP (Hypertext Transfer Protocol, FTP (File Transfer Protocol) and ASP (Active Server Pages) enabled Database: SQL Data Sources - Database Engines such as: MS Access, MS SQL Server, Oracle, Sybase, MySQL, DB2, etc.
5
Schematic of Connections HTTP SERVER N T / 2000 I I S DATABASE A S P ODBC Browser Internet
6
ODBC – Open Data Base Connectivity Microsoft’s middleware for connecting applications to a variety of SQL Data Sources with provided drivers. At the Control Panel of the Server – Register a Data Source Name (DSN) by associating a name with a path to a target database and the appropriate driver.
7
Example of an ODBC Application Example of an ODBC application
8
<HTML><HEAD> : Sample Form Elements HTML Form
9
Sample HTML Feedback Form The Cookbook Group (S99) had developed a Feedback Form for their shop. On submission of the form, the data will be posted to an Access Database which was created to receive the posted data. The form calls FEEDBACK.ASP which in turn inserts the data into the database with an Feedback Form FEEDBACK.ASP Feedback Form FEEDBACK.ASP SQL INSERT statement. The DSN: CBFEEDBACK used in the file was registered with ODBC and is connected to a database called Feedback.mdb. SQL INSERT statement. The DSN: CBFEEDBACK used in the file was registered with ODBC and is connected to a database called Feedback.mdb.
10
Generated SQL Statement INSERT INTO FEEDBACK (name, email, findeverything, easynavigate, (name, email, findeverything, easynavigate, seemoreof, american, asian, french, italian, mediterranean, mexican, cocktails, desserts, comments) VALUES('......','......','......',........); Column Names Table Name Text Values in Single Quotes
11
Sample HTML Query Form Query FormQuery Form
12
Sample Query Form title>Access DB to Web Demo Query Form Access DB to Web Demo Query Form Great Plains Music and Video, Inc. Great Plains Music and Video, Inc. Catalog Query Form Catalog Query Form <hr> Item to Search for: Item to Search for: <p><hr></form>
13
Output of the Query
14
What is the SQL Data Source? Another Query Form Query FormQuery Form Sample HTML Query Form Query FormQuery FormMicrosoft Access Access or Oracle Microsoft SQL Server SQL Server2000 or
15
Active Server Pages (ASP) An ASP file contains HTML and VBScript code and resides on the server. When this ASP file is requested, the server will execute the VBScript code. The execution of the code will produce additional HTML, data from a data source, computation results, etc. The end result is a HTML file being sent back to the requester’s browser. INVQUERY.ASP
16
Segment from ASP Program (1 of 2) <% SET CONN = Server.CreateObject("ADODB.Connection") CONN.open "WEBGTP","","" SQL = "SELECT format([item no],'#####') as [item number],[item description], [item number],[item description], format([on hand],'#####') as [In Stock], format([on hand],'#####') as [In Stock], format([price],'currency') as [List Price], "'"+ format([price],'currency') as [List Price], "'"+ request.form("DESC") +"'" as [DESCR] FROM INV request.form("DESC") +"'" as [DESCR] FROM INV WHERE [item description] LIKE '%"+ WHERE [item description] LIKE '%"+ request.form("DESC")+"%'" request.form("DESC")+"%'" SET RS = Server.CreateObject("ADODB.Recordset") RS.Open SQL, CONN, 3, 3 RS.MoveFirst RS.MoveFirst %>
17
Segment from ASP Program (2 of 2) <tr> <% RS.MoveNext Loop %>
18
Examples of Connecting a Database to a Web Application The End
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.