Presentation is loading. Please wait.

Presentation is loading. Please wait.

Server-Side Application and Data Management IT IS 3105 (Spring 2010)

Similar presentations


Presentation on theme: "Server-Side Application and Data Management IT IS 3105 (Spring 2010)"— Presentation transcript:

1 Server-Side Application and Data Management IT IS 3105 (Spring 2010)
Lecture 2

2 LAMP/WAMP Architecture
LAMP: Linux, Apache, MySQL, and PHP WAMP: Windows, Apache, MySQL, and PHP HTTP Request: HTTP Response Apache Web Browser MySQL PHP Operating System Result Set SQL Query Operating System Server Client

3 CGI Common Gateway Interface

4 CGI: Common Gateway Interface
Common Gateway Interface (CGI) A standard for interfacing external applications with information servers, such as HTTP or Web servers Plain HTML documents that a Web server retrieves are static They exist in a constant state A text file that doesn't change without human intervention CGI programs are executed in real-time They can output dynamic information responding to client requests

5 CGI: Common Gateway Interface
Static Web Pages Client browser requests a static web page from a web server Web server looks for the file locally or on a file server File returned to web server Server returns file to browser Browser displays content http request http response

6 CGI: Common Gateway Interface
Dynamic Client browser requests a file from a web server Web server notices this file is special – it is executable The web server must be configured for this The file is executed Request parameters (if present) are examined External data is retrived (if requested) Response is generated Typically a customized HTML file Server returns generated data to browser Browser displays content Executable program RDB

7 CGI Basics Run any executable program C

8 C vs Java C – Compiled Pros Cons One time compile Runs fast
Must be loaded every time it executes Can be a slow process Must be recompiled for every change Executable will only run on one platform May be difficult to port to another platform

9 C vs Java Java – “interpreted” Cons Pros “Interpreted”
Runs slower Still need a compilation Pros Once loaded stays loaded Fast second and subsequential runs Compiled p-code OS/HW indepenent

10 Typical CGI development
Spec/Design the solution Base/Navigation/Intermediate HTML pages Typically static pages Spec/Design HTML pages with forms Pass data to CGI programs GET vs POST GET: Pass data as part of the URL Visible Used for Idempotent requests, Static requests Requests that don’t change the server state e.g. don’t write data to the server POST Pass date as part of the HTTP request More secure Used when the state of the server may be changed Write data to the server Create and “order”

11 Typical CGI development
Design the solution (cont) Spec/Design the executable code Choose a program language Must be able to write to STDOUT Typical choices: C/C++ Fortran PERL TCL Any Unix shell Visual Basic AppleScript

12 Design the solution (cont)
Spec/Design the executable code (cont) Write code to extract the data passed from the Form If appropriate Process the data from the form Retrieve data from the database Create the HTML to send back to the Client

13 Example (php) http://sis-43spp11-pc/grades/grades.htm
Note how the program is called in this top level page pc/grades/Add_Student_Form.htm Note how the program is called in this case

14 <html> <head><title>Display Students</title></head> <body> <h1>List of Students</h1><hr> <table dir="ltr" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td valign="top" width="1%“> </td> <td valign="top" width="24"></td> <td valign="top"> <?php $server = 'localhost‘; $user = 'root‘; $pass = 'xyz'; $mydb = 'gradesdb'; $connect = mysql_connect($server, $user, $pass); if (!$connect){ die ("Cannot connect to $server using $user"); } else { $sqlcommand = "select * from students"; $con_results = mysql_select_db ($mydb); if (!$con_results) { print "con results: $con_results\n“; die ("Could not connect to db"); } print "<br>The query is: $sqlcommand<br>"; $results_id = mysql_query($sqlcommand, $connect); if (!$results_id) { // did it get the data print "results_id: $results_id <br>\n“; die ("Could not select students from db"); // no! else { // got it! print "<p>Students in database</p>\n"; print "<table border='1'>\n"; print "<tr>\n"; print " <th>ID</th>\n“; print " <th>First Name</th>\n“; print " <th>Last Name</th>\n"; print "</tr>\n"; while ($row = mysql_fetch_row($results_id)) { foreach ($row as $field) // note the foreach! { print " <td>$field</td>\n“; } } // end while print "</table>\n"; } // end if..else.. results_id } // end if..else.. con_results } // end if..else.. connect ?> <p><a href="grades.htm">Return to Main</a></p> </td> </tr> </table> <hr> </body> </html>

15 Display Students.php Display_students.php


Download ppt "Server-Side Application and Data Management IT IS 3105 (Spring 2010)"

Similar presentations


Ads by Google