Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Connecting Databases to the Web October 30 th, 2001 Xinguang Sheng Marcus Haebler.

Similar presentations


Presentation on theme: "1 Connecting Databases to the Web October 30 th, 2001 Xinguang Sheng Marcus Haebler."— Presentation transcript:

1 1 Connecting Databases to the Web October 30 th, 2001 Xinguang Sheng Marcus Haebler

2 Connecting Databases to the Web2 Outline How Does Web application architecture evolves Common Gateway Interface (CGI) Java Applets Server Extensions PHP Active Server Pages/ Java Server Pages What else is out there? Architectures Extended PHP example

3 Connecting Databases to the Web3 First Generation Architecture

4 Connecting Databases to the Web4 Second Generation Architecture

5 Connecting Databases to the Web5 Next Generation Architecture

6 Connecting Databases to the Web6 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 Common Gateway Interface (CGI) HTTP-Request HTML-File Web-Server File-System Load File File HTML? HTML Execute Program Program?Output I/O, Network, DB

7 Connecting Databases to the Web7 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 forked for every request -Security: CGI programmer is responsible for security -Updates: To update layout, one has to be a programmer CGI: Discussion

8 Connecting Databases to the Web8 Java Applets Web-Server HTTP-Request HTML-File Web-Server File-System Load File File Load Applet... Java-Class Requests Java-Classes Execute Applet... Java Virtual Machine (JVM) Server- Process

9 Connecting Databases to the Web9 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 (Java VM but … can be configured) Note: Server-Process can be written in any language Java Applets: Discussion

10 Connecting Databases to the Web10 Java-Server-Process DB Access in Java Sybase Java Applet TCP/UDP IP Oracle... JDBC- Driver JDBC Driver manager

11 Connecting Databases to the Web11 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 Server Extensions

12 Connecting Databases to the Web12 Server Extensions: The Basic Idea File-System Web-Server HTTP-Request HTML-File Web-Server Load File File HTML? HTML I/O, Network, DB Script? Output Server Extension

13 Connecting Databases to the Web13 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 Server Extensions

14 Connecting Databases to the Web14 Active Server Pages (ASPs) -Available in IIS and Personal Web Server -Based on VBScript, Jscript -Modular Object Model -Active Server Components -Active Data Objects (ADO) for Database access -In MS.NET ASP+, ADO+ … Active Server Pages File-System Web-Server HTTP-Request HTML-File Load File ASP-File HTML ASP-ScriptOutput I/O, Network, DB Active Server Page Scripting Engine Active Server Components

15 Connecting Databases to the Web15 ColdFusion File-System Web-Server HTTP-Request HTML-File Web-Server Load File File HTML? HTML CF Script? HTML Cold Fusion Server Extension Cold Fusion Application Server ODBC-DriverNative DB Email Directories COM/CORBA

16 Connecting Databases to the Web16 ColdFusion: Simple Query Proprietary Scripting Language CFML - similar to other scripting languages SELECT * FROM Persons Person List Name: #Name# Age: #Age# Salary: $#Sal# Person List Name: Tom Age: 45 Salary: $45000 Name: Jim Age: 38 Salary: $40000 Name: Karen Age: 26 Salary: $32000

17 Connecting Databases to the Web17 ColdFusion: Form Handling <FORM ACTION="http://www.abc.com/cf/pf.cfm"> Find Person Person Name Tom Age: 45 Salary: $45000 <A HREF=“www.tom.com” Homepage SELECT * FROM Persons WHERE Name=#Form.PName# #Name# Age= #Age# Salary= $#Sal# Homepage

18 Connecting Databases to the Web18 ColdFusion: Misc. Issues Site admin 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 access the database through the application server Application server is also gateway to database for the ColdFusion IDE (ColdFusion Studio)

19 Connecting Databases to the Web19 PHP 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 File-System Web-Server HTTP-Request HTML-File Load File PHP-File HTML PHP-ScriptOutput Database APIs, other APIs SNMP, IMAP, POP3, LDAP,... PHP Module Web-Server

20 Connecting Databases to the Web20 PHP: A Simple Example <?PHP $db = mysql_connect("localhost", "dbuser"); mysql_select_db("mydb",$db); $result = mysql_query("SELECT * FROM employees",$db); ?> NAME POSITION <?PHP while ($myrow = mysql_fetch_row($result)) { printf(" %s %s %s \n", $myrow[1], $myrow[2], $myrow[3]); } ?>

21 Connecting Databases to the Web21 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 3 installed on fling.seas.upenn.edu Version 4.0.2 latest version (zend engine) -more OO features -is based on a different, faster scripting engine -more modular architecture The number of functions is steadily increasing

22 Connecting Databases to the Web22 Java Server Pages

23 Connecting Databases to the Web23 JSP Example—Hello.jsp My first JSP page

24 Connecting Databases to the Web24 And the Output IS My first JSP page Hello World

25 Connecting Databases to the Web25 What Else Is Out There? Java Server Pages (JSP) -similar to PHP Java Servlets -very similar to CGIs A couple of solutions from Oracle -PENN ExpressApp is based on OWS various web shop applications -all of them use a more or less sophisticated scripting language and a lot more...

26 Connecting Databases to the Web26 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)

27 Connecting Databases to the Web27 Architectures The architecture type depends on kind and number of servers involved Different archictures different advantages and disadvantages Generally we can distinguish between different types: -2-tier architecture -3-tier architecture -n-tier architecture What matters: SPEED

28 Connecting Databases to the Web28 Web-Server 2-tier Architecture Web server plus module connecting to database, LDAP, IMAP,... HTTP-Request HTML-File Module DBDirectory Mail Server SNMP 1 2

29 Connecting Databases to the Web29 2-tier Architecture Advantages: -easy and fast to setup -easy to administrate Disadvantages: -not fail safe (single point of failure) -scales badly on high loads

30 Connecting Databases to the Web30 3-tier Architecture Web server plus application server connecting to database, IMAP,... DB Mail Server SNMP 1 3 2 Web Server [Cluster] Application Server [Cluster] Other Servers [Cluster] DB Repl.

31 Connecting Databases to the Web31 3-tier Architecture Advantages: -better scalabilty -more reliable through failover mechanisms -offers better load balancing Disadvantages: -complicated to set up an maintain

32 Connecting Databases to the Web32 Architectures: Usage 2-tier -Apache-PHP plus Database etc. 3-tier -ColdFusion 4.x, BEA Weblogic -Oracle Web Application Server? n-tier -big sites with custom systems like Yahoo, Amazon.com, eBay Classification not always 100%

33 Connecting Databases to the Web33 Technology Choices PHP/{Oracle|mySQL} – Minimum Setup use fling or Eniac. ASP/Access/ODBC -- Need MS IIS JSP/{Oracle|mySQL}/JDBC -- Need Tcomcat or Apache+JServ Any Other Choices?

34 Connecting Databases to the Web34 Extended PHP Example browser

35 Connecting Databases to the Web35 Extended PHP Example browser

36 Connecting Databases to the Web36 Plain HTML Simple SQL Web Interface for Movie Table Simple SQL Web Interface for Movie Table [PHP code here] browser

37 Connecting Databases to the Web37 Table Generation (Part 1) <?php /* check for query, if empty describe movies */ if (!isset($query)) { $query = "describe movies"; } else { $query = stripslashes($query); print " Your query: \"". $query. "\"\n"; } $result = mysql_query($query, $conID) or die ("Invalid query"); // disable error reporting $eLevel = error_reporting(0); ?> browser

38 Connecting Databases to the Web38 Table Generation (Part 2) <?php /* generate table header or catch INSERT, DELETE and UPDATE statements */ if (mysql_affected_rows($conID) > 0) print " affected ". mysql_affected_rows($conID). " row(s)! \n"; if (mysql_num_rows($result) > 0) { $noFields = mysql_num_fields($result); print " \n \n"; for ($i = 0; $i < $noFields; $i++) print " ". mysql_field_name($result, $i). " \n"; print " \n"; while ($row = mysql_fetch_array ($result)) { print " \n"; for ($i = 0; $i < $noFields; $i++) print " ". $row[$i]. " \n"; print " \n"; } print " \n"; } ?> browser

39 Connecting Databases to the Web39 Links Software: -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.com/ -Oracle Technet: http://technet.oracle.com/ -PHP: http://www.php.net/, http://www.zend.com/ Others: -c|net: http://www.builder.com/ -DevShed: http://www.devshed.com/Server_Side/ -Webmonkey: http://www.webmonkey.com/


Download ppt "1 Connecting Databases to the Web October 30 th, 2001 Xinguang Sheng Marcus Haebler."

Similar presentations


Ads by Google