Download Connecting Databases to the web

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Microsoft Jet Database Engine wikipedia , lookup

Microsoft Access wikipedia , lookup

Oracle Database wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Database model wikipedia , lookup

Clusterpoint wikipedia , lookup

Team Foundation Server wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Transcript
Connecting Databases to the Web
January 31th, 2000
Seree Chinodom
1
How the Web Works
• The old fashioned way:
Web-Browser
HTTP-Request
GET ...
Web-Server
HTML-File
Load File
HTML-File
File-System
January , 2000
Connecting Databases to the Web
2
How the Web Works
• All pages are static
• Need to generate web pages on the fly depending
on user input
?
January , 2000
Connecting Databases to the Web
3
Common Gateway Interface (CGI)
• Some files on server are interpreted as programs
depending on either ext., flag or special directory
• Program is invoked and generates MIME header
and HTML on stdout
Web-Server
HTTP-Request
Web-Server
HTML
HTML-File
Output
File-System
Load File
HTML?
Program?
Execute Program
January , 2000
File
Connecting Databases to the Web
I/O, Network, DB
4
CGI: Discussion
Advantages:
- Standardized: works for every web-server, browser
- Flexible: Any language (C++, Perl, Java, …) can be used
Disadvantages:
- Statelessness: query-by-query approach
- Inefficient: new process for every request
- Security: CGI programmer is responsible for security
- Updates: To update layout, one has to be a programmer
January , 2000
Connecting Databases to the Web
5
Java Applets
Web-Server
HTTP-Request
Web-Server
Load File
File-System
HTML-File
Load Applet...
Java-Class Requests
File
Java-Classes
ServerProcess
Execute Applet...
Java Virtual
Machine (JVM)
January , 2000
Connecting Databases to the Web
6
Java Applets: Discussion
Advantages:
- Platform independent: works for every web-server and
browser supporting Java
Disadvantages:
- Standalone Character:
· Entire session runs inside applet
· HTML forms are not used
- Inefficient: loading can take a long time ...
- Resource intensive: Client needs to be state of the art
- Restrictive: can only connect to server where applet was
loaded from (restrictions of Java VM)
Note: Server-Process can be written in any language
January , 2000
Connecting Databases to the Web
7
DB Access in Java
Java Applet
TCP/UDP
IP
Java-Server-Process
JDBC Driver manager
January , 2000
JDBCDriver
JDBCDriver
JDBCDriver
Sybase
Oracle
...
Connecting Databases to the Web
8
Server Extensions
Previous Approaches
- Platform independent and standardized
- Simple interface
- Lots of programming necessary
- Inefficient
Server Extensions
- Server is extended with handler/module
- One handler for all incoming requests
- Much more efficient
January , 2000
Connecting Databases to the Web
9
Server Extensions: The Basic Idea
Web-Server
Web-Server
HTTP-Request
Load File
HTML
HTML?
HTML-File
Output
File
Script?
Server Extension
January , 2000
File-System
I/O, Network, DB
Connecting Databases to the Web
10
Server Extensions
• API depends on Server vendor:
- Apache Foundation Apache Server: Apache API
- Microsoft Internet Information Server: ISAPI
- Netscape Enterprise Server: NSAPI
• One can define it’s own server extension,
e.g.
- Authentication module
- Counter module
January , 2000
Connecting Databases to the Web
11
A Quick Look at Market Shares
Market Share for Top Servers Across All Domains
August 1995 - October 1999
Source: http://www.netcraft.com/survey/
January , 2000
Connecting Databases to the Web
12
ColdFusion
Web-Server
Web-Server
HTTP-Request
HTML
Load File File-System
HTML?
HTML-File
File
HTML
CF Script?
Cold Fusion Server
Extension
Cold Fusion Application
Server
ODBC-Driver
Native
Email
Directories
DB
January , 2000
Connecting Databases to the Web
DB
COM/CORBA
13
ColdFusion: Simple Query
• Proprietary Scripting Language CFML - similar to
other scripting languages
<CFQUERY NAME=“PersonList”
DATASOURCE=“PersonDB”>
SELECT * FROM Persons
</CFQUERY>
<HTML>
<BODY>
<H1> Person List </H1>
<CFOUTPUT QUERY=“PersonList”>
<B>Name:</B> #Name#
<B>Age:</B> #Age#
<B>Salary:</B> $#Sal# <BR>
</CFOUTPUT>
</BODY>
</HTML>
January , 2000
<HTML>
<BODY>
<H1> Person List </H1>
<B>Name:</B> Tom
<B>Age:</B> 45
<B>Salary:</B> $45000 <BR>
<B>Name:</B> Jim
<B>Age:</B> 38
<B>Salary:</B> $40000 <BR>
<B>Name:</B> Karen
<B>Age:</B> 26
<B>Salary:</B> $32000 <BR>
</BODY>
</HTML>
Connecting Databases to the Web
14
ColdFusion: Form Handling
<CFQUERY NAME=“PersonInfo”
DATASOURCE=“PersonDB”>
SELECT * FROM Persons
WHERE Name=#Form.PName#
</CFQUERY>
<HTML>
<BODY>
<CFOUTPUT QUERY=“PersonInfo”>
<HTML>
<H1> #Name# </H1>
<BODY>
<UL>
<FORM
<LI><B>Age:</B> #Age#
ACTION="http://www.abc.com/cf/pf.cfm">
<LI><B>Salary:</B> $#Sal#
<H1> Find Person </H1>
<LI><A href=“#URL#”><B>Homepage</B>
Person Name <INPUT NAME="PNAME">
</A>
<p>
</UL>
<input type="submit" value="Find">
</CFOUTPUT>
</FORM>
</BODY>
</BODY>
</HTML>
</HTML>
January , 2000
<HTML>
<BODY>
<H1> Tom </H1>
<UL>
<LI><B>Age:</B> 45
<LI><B>Salary:</B> $45000
<LI><A href=“www.tom.com”
<B>Homepage</B></A>
</UL>
</BODY>
</HTML>
Connecting Databases to the Web
15
ColdFusion: Misc. Issues
• Siteadmin sets up data sources very similar to
the handling of ODBC data sources in MS
Windows
• In fact ColdFusion combines techniques to
access databases:
- Generation of HTML code
- Java Applets embedded via <CFGRID></CFGRID>
access the database through the application server
• Application server is also gateway to database
for the ColdFusion IDE (ColdFusion Studio)
January , 2000
Connecting Databases to the Web
16
Active Server Pages
• Active Server Pages (ASPs)
- Available in IIS and Personal Web
Server
- Based on VBScript, Jscript
- Code in <% ... %>
- Modular Object Modell
HTTP-Request
- Active Server
Components
HTML-File
- Active Data Objects for
Database access
Web-Server
Load File
File-System
HTML
ASP-File
Output
ASP-Script
Active Server Page
Scripting Engine
I/O, Network, DB
Active Server
Components
January , 2000
Connecting Databases to the Web
17
PHP
Web-Server
Web-Server
HTTP-Request
Load File
File-System
HTML
HTML-File
PHP-File
Output
PHP-Script
PHP
Module
January , 2000
Database APIs,
other APIs SNMP,
IMAP, POP3,
LDAP, ...
How does PHP differ
from ASP and CF?
• Free, open source
• Many client libraries
integrated
• Runs on any web
server supporting
CGIs (MS Windows
or Unix)
• Module version for
Apache
Connecting Databases to the Web
18
PHP: an Example
<HTML>
<BODY>
<?PHP
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
$result = mysql_query("SELECT * FROM employees",$db);
?>
<TABLE BORDER=1>
<TR><TD>NAME</TD><TD>POSITION</TR>
<?PHP
while ($myrow = mysql_fetch_row($result)) {
printf("<tr><td>%s %s</td><td>%s</td></tr>\n",
$myrow[1], $myrow[2], $myrow[3]); }
?>
</TABLE>
</BODY>
</HTML>
January , 2000
Connecting Databases to the Web
19
PHP: Misc. Issues
• Syntax Perl/C like
• Form fields are available as variables in
following page
• has e.g. image and PDF generation on the fly
• some OO features (e.g. classes)
• Version 4 in beta test has
- more OO features
- is based on a different, faster scripting engine
- more modular architecture
• The number of functions is steadily increasing
January , 2000
Connecting Databases to the Web
20
Databases Usually Used
• ASP
- MS Jet Engine (DB engine behind MS Access)
- MS SQL Server
- Oracle (ODBC)
• ColdFusion
- Oracle (native driver support)
- Informix (native driver support)
- Sybase (native driver support)
• PHP
-
MySQL (linked in client library)
mSQL (linked in client library)
Postgres (linked in client library)
Oracle (linked in client library)
January , 2000
Connecting Databases to the Web
21
What Else Is Out There?
• Oracle Application Server (formerly known as
OWS)
- 3-tier architecture
- PENN ExpressApp is based on OWS
• Informix Web datablade
• Servlets for Java based web server
• various web shop applications
- all of them use a more or less sophisticated scripting
language
• and a lot more ...
January , 2000
Connecting Databases to the Web
22
Architectures
• The architecture is the kind and number of
servers involved
• Different architectures different advantages and
disadvantages
• Generally we can distinguish between
three different types:
- 2-tier architecture
- 3-tier architecture
- 4-tier architecture
January , 2000
Connecting Databases to the Web
23
2-tier architecture
• Web server plus module connecting to
database, LDAP, IMAP, ...
HTTP-Request
1
Web-Server
HTML-File
Module
2
DB
Directory
Mail
Server
January , 2000
SNMP
Connecting Databases to the Web
24
2-tier architecture
• Advantages:
- easy and fast to setup
- easy to administer
• Disadvantages:
- not fail safe
- scales badly on high loads
January , 2000
Connecting Databases to the Web
25
3-tier architecture
• Web server plus application server connecting to
database, IMAP, ...
Web
Server
[Cluster]
Application
Server
[Cluster]
Other Servers
[Cluster]
DB
January , 2000
DB
Repl.
DB
Mail
Server
1
2
3
SNMP
Connecting Databases to the Web
26
3-tier architecture
• Advantages:
- better scalability
- more reliable through failover mechanisms
- offers better load balancing
• Disadvantages:
- already complicated to set up
- who is responsible for load balancing?
January , 2000
Connecting Databases to the Web
27
4-tier architecture
Web
Server
[Cluster]
Request
Router
Request
Router
Request
Router
2
Application
Server
[Cluster]
3
Other Servers
[Cluster]
DB
January , 2000
DB
Repl.
DB
Mail
Server
1
4
SNMP
Connecting Databases to the Web
28
4-tier architecture
• Advantages:
-
even better scalability
better failover mechanisms
Request routers offer better load balancing
Easier to administer (number of request router
usually small)
• Disadvantages:
- initial setup very complicated
January , 2000
Connecting Databases to the Web
29
Architectures: Usage
• 2-tier
- Apache-PHP plus Database etc.
• 3-tier
- ColdFusion 4.0x
- Oracle Web Application Server?
• 4-tier
- Web shops like Intershop, ...
- ColdFusion 4.5x?
- Oracle Application Server?
Classification not always 100% clear
January , 2000
Connecting Databases to the Web
30
Security Issues
• Complicated architecture
 More potential for glitches
• Protection of users from each other
• Web server with DB
 nice way for hacker into main database
• ...
January , 2000
Connecting Databases to the Web
31
Links
•
Products:
-
•
Apache: http://www.apache.org/
ASP: http://msdn.microsoft.com/workshop/server/default.asp
ColdFusion: http://www.allaire.com/coldfusion/
MySQL: http://www.mysql.com/
Oracle: http://www.oracle.net/
Oracle Technet: http://technet.oracle.net/
PHP: http://www.php.net/
Others:
-
c|net: http://www.builder.com/
DevShed: http://www.devshed.com/Server_Side/
Webmonkey: http://www.hotwired.com/webmonkey/
January , 2000
Connecting Databases to the Web
32