Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web Programming for DB Applications Yuen-Hsien Tseng 2006/04/18.

Similar presentations


Presentation on theme: "Web Programming for DB Applications Yuen-Hsien Tseng 2006/04/18."— Presentation transcript:

1 Web Programming for DB Applications Yuen-Hsien Tseng 2006/04/18

2 Web Environment Browser: IE, Firefox, … Web Server: Apache, IIS, … DBMS: Access, MS SQL, MySQL, Oracle, … Web Programming Env.: CGI, ASP, JSP, PHP Web Server DBMS/ DB server P1 P2 Pn CGI ODBC ASP PC Browser DB Client Internet Server

3 Web Server Administration Virtual Path: –Root dir: Where is http://localhost/ in file systemhttp://localhost/ Default index page: index.htm[l], welcome.htm, … –User dir: How http://localhost/~sam/ maps to d:/sam/public_htmlhttp://localhost/~sam/ –How http://localhost/demo/ maps to d:/demohttp://localhost/demo Executable and non-executable files –Configurations and File permissions –http://www.cgi101.com/book/connect/winxp.html Port number

4 Apache Configuration An example configuration to run a program: Alias /~tseng/ "D:/Sam/public_html/" Options Indexes MultiViews ExecCGI AllowOverride AuthConfig Order allow,deny Allow from all

5 CGI (Common Gateway Interface) Messages sent to Web server –print “Content type: text/html\n\n …”; Message received from Web server –URL-encoding/decoding –method = Get or Post http://localhost/test.pl?name=sam&age=40 Name: Age:

6 Introduction to Perl Invented by Larry Wall in late 1980’s Combined the merits of many languages –C/C++, Unix Shell, … –String Processing, Regular Expression, … Suitable for –File management –String manipulation –Process control Lot of resources in source codes –http://www.cpan.org/

7 Perl Basics Data Types –Scalar (numeric, strings), array, hash, reference Flow control –If elsif else, for, foreach, while, next, last Special variables Subroutines Regular Expressions Reference and Object-oriented programming

8 Data types Scalar –$a=1; $b=1.2; $a = $a. $b. “=sam”; Array –@C=(1, “e”, 3.4); $c=$C[1]; @a = @C[0..1]; –$a = pop @C; $b= unshift @C; shift @C, ‘c’; push @a, ‘e’; Hash –%H=(‘sam’, 4, ‘joe’, 2); %G=(‘sam’=>4, ‘joe’=>2); –%T=reverse %H; Reference –$b=\@C; $a=$b->[0]; –$a=\%H; $b=($a->{‘sam’} == 4)?’Yes’:”no”; http://www.cgi101.com/book/ch2/text.html

9 Flow control foreach (@A) { next if /^\d/; # next unless not /^\d/; last if /^\s*$/; print ; } for($i=0; $i<$n; $i+=2) { print $A[$i]; } While ( ) { … }

10 Special Variables $_, @_, @ARGV Sort { $b eq $a } keys %H; Sort { $H{$b} $H{$a} } keys %H;

11 Subroutines ($r, $i) = &add($r1, $i1, $r2, $i2, “no”, “use”); sub add { my($r1, $i1, $r2, $i2, @r) = @_; return ($r1+$r2, $i2+$i2); }

12 Regular Expressions print "It matches\n" if "Hello World" =~ /World/; –$greeting = "World"; –print "It matches\n" if "Hello World" =~ /$greeting/; "Hello World" =~ /world/; # doesn't match, case sensitive "Hello World" =~ /o W/; # matches, ' ' is an ordinary char "Hello World" =~ /World /; # doesn't match, no ' ' at end Metacharacters : {}[]()^$.|*+?\ –"2+2=4" =~ /2+2/; # doesn't match, + is a metacharacter –"2+2=4" =~ /2\+2/; # matches, \+ is treated like an ordinary + – /[yY][eE][sS]/; # match 'yes' in a case-insensitive way # 'yes', 'Yes', 'YES', etc. –/yes/i; # also match 'yes' in a case-insensitive way –/item[0-9]/; # matches 'item0' or... or 'item9' –/[0-9a-fA-F]/; # matches a hexadecimal digit $time =~ /(\d\d):(\d\d):(\d\d)/; # match hh:mm:ss format –$hours = $1; $minutes = $2; $seconds = $3;

13 More tutorials Reference –See c:/Perl/html/lib/Pod/perlreftut.html Object-oriented programming –See c:/Perl/html/lib/Pod/perltoot.html

14 CGI Module and Environment Variables See –http://www.cgi101.com/book/ch3/text.htmlhttp://www.cgi101.com/book/ch3/text.html –c:/Perl/html/lib/CGI.html Use CGI; print param(‘name’); print "Caller = $ENV{HTTP_REFERER}\n";


Download ppt "Web Programming for DB Applications Yuen-Hsien Tseng 2006/04/18."

Similar presentations


Ads by Google