database-driven_webpages.ppt

  • 2,364 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
2,364
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
12
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • CGI: Perl (Server side) Php (Server side) JavaScript (Server or Client side) Cold Fusion ASP ((Visual) Basic) LabVIEW Regular expressions Databases (Microsoft Access, MySQL; normalization) DB management (within windows (Access), Web (MySQL & Access 2k)) Interfacing HTML (post & get methods, cookies) Scripts (server side) Security UVa ITC classes for these programs General advice: Think through & organize db well before implementing when defining tables, set default values
  • http://searchdatabase.techtarget.com/sDefinition/0,,sid13_gci211895,00.html
  • http://searchdatabase.techtarget.com/sDefinition/0,,sid13_gci211895,00.html
  • MySQL tools: http://databases.about.com/cs/shareware/

Transcript

  • 1. UVa ITC Research Computing Support Fall, 2002 Presented by the Research Computing Support Group David Drake, Kathy Gerber, Ed Hall, Tim F. Jost Tolson
    • Overview of Research Hardware, Software, Support & Storage: Tuesday, September 10, 3:30 PM
    • Statistical Software – Thursday, September 12, 3:30 PM
    • Mathematical & Visualization Software – Tuesday, September 17, 3:30 PM
    • High Performance Computing – Thursday, September 19, 3:30 PM
    • FEMLAB Seminar: Multiphysics Modeling – Friday, Sept. 27 at 10:00 AM
    • Introduction to IDL – Wednesday, October 9 at Noon
    • Database-Based Webpages – Wednesday, October 23 at 3 pm
    • Maple 8 – Wednesday, November 20 at 3 pm
  • 2. Database-Driven Webpages
    • By: David Drake
    • Research Computing Support Center
    • Phone: 243-8800 || Fax: 243-8765
    • E-Mail: [email_address]
    • http://www. itc .Virginia. edu /researchers
  • 3. Databases and the Web
    • Databases in the Abstract
    • Creating Databases using Relational DataBase Management Systems (RDBMSs)
    • Databases and Web Interfaces
  • 4. I. Databases in the Abstract
    • Definition
    • Normalization
    • Structure
    • Language
  • 5. I. A. Definition
    • A database is an organized collection of data whose content must be quickly and easily
      • Accessed
      • Managed
      • Updated
    • A relational database is one whose data are split up into tables , sometimes called relations
  • 6.
    • First Normal Form ( 1NF )
      • All attributes are single valued & non-repeating
    • Second Normal Form ( 2NF )
      • Must be 1NF & must have primary key
      • Each non-primary key attribute must be functionally dependent on primary key
    • Third Normal form ( 3NF )
      • Must be 2NF
      • Each non-primary key attribute must be dependent only on primary key
    I. B. Normalization (read logical organization)
  • 7. I. C. 1. Tables (Relations)
    • Each column constitutes an attribute
    • Each row constitutes a record or tuple
    Attribute 2 (column 2) Record 2 (tuple 2) Record 1 (tuple 1) Attribute 1 (column 1)
  • 8.
    • Primary
      • An attribute or group of attributes which uniquely identifies each record in a table
      • May not be a Null value
    • Foreign
      • used primarily for enforcing referential integrity, but also for establishing relationships between the two tables
    I. C. 2. Keys
  • 9.
    • One-to-one (1-to-1)
    • One-to-many (1-to-M or 1-to-  )
    • Many-to-Many (M-to-M or  -to-  )
    I. C. 3. Relationships
  • 10. I. D. Structured Query Language (SQL)
    • Pronounce “Sequel” or “Ess Que Ell”
    • Industry standard language of (Relational) Databases
    • Allows for complete
      • Table Creation, Deletion, Editing
      • Data extraction (Queries)
      • Database management & administration
  • 11. II. Creating Databases using RDBMSs
    • Microsoft Access
      • Creating Tables
      • Entering, Importing, Editing, & Viewing Data
      • Defining Relationships
      • Constructing Queries
    • MySQL … ( Documentation )
      • Where to put it (servers at UVa)
      • Ditto MS Access
    • Others
      • mSQL, PostGreSQL, Oracle, DB2, Informix, Sybase, Empress, Adabas (available with StarOffice), ….
  • 12. III. Databases and Web Interfaces (What you need to get started)
    • Requirements for a Database Web Interface
    • Where to Put Your Database and Scripts
    • Server-Side Scripting Languages
      • ASP
      • Cold Fusion
      • Perl
      • PHP
  • 13. III. A. Requirements for a Database Web Interface
    • Your database (Access, MySQL)
    • A Web server with appropriate RDBMS
    • A way of connecting the two (Common Gateway Interface [CGI] scripts and SQL)
    • Security concerns
  • 14. III. B. Where to Put Your Database and Scripts
    • Academic side of UVa
      • Access
        • ESERVICES es-web1 (web.virginia.edu)
      • MySQL
        • MySQL server ( dbm1. itc . virginia . edu )
        • Home directory (www.people – accessible through blue.unix), faculty, curry, avery, minerva (www.virginia.edu), jm.acs (www.itc.virginia.edu)
    • Medical side of UVa
      • See the UVa Health System’s Web Development Center
  • 15. Active Server Pages (ASP)
    • When a browser calls an ASP document, the ASP Server reads the .asp document and
      • Substitutes appropriate files for the (server-side) include statements
      • Runs the ASP code (see the VBScript and JScript Tutorial and Language References as well as the ASP Guide )
      • Returns the resulting HTML code to the browser
    • Example ( code , copy of database )
  • 16. ASP Key Points (1)
    • ASP code enclosed in: <% VBScript code %>
    • Everything outside is HTML
    • The result of the combined HTML and ASP code must be a “standard” HTML document, e.g.:
      • <!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Final//EN&quot;> <html> <head> <title>Miracle Drug Study</title> <meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;> <meta name=&quot;Description&quot; content=&quot;&quot;><meta name=&quot;Keywords&quot; content=&quot;&quot;> <link rel=STYLESHEET type=&quot;text/css&quot; href=&quot;&quot;> </head> <body> </body> </html>
  • 17. ASP Key Points (2)
    • Connect with database:
      • Create connection object:
        • set conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
      • Open connection:
        • conn.open(&quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=f:webdatabase escompstudy.mdb&quot;)
    • Submit a (read-only) Query:
      • Generate SQL statement:
        • SQL = &quot;SELECT FirstName, LastName, DOB, Gender FROM Patients WHERE Gender = '&quot; & Gender & &quot;' ORDER BY FirstName DESC&quot;
        • set Patients = conn.execute(SQL)
  • 18. ASP Key Points (3)
    • Move through the data records:
      • do while NOT Patients.eof Name = Patients(0) & &quot; &quot; & Patients(1) Patients.MoveNext loop
    • Add to or edit table:
      • Create and open Record Set object:
        • set RS = Server.CreateObject(&quot;ADODB.Recordset&quot;) RS.Open “ table name &quot;, conn, , adLockOptimistic, adCmdTable (where adLockOptimistic = 3, adCmdTable = 2)
  • 19. ASP Key Points (4)
    • Add to or edit table (continued):
      • Create new record, Edit, & Update:
        • RS.AddNew RS(“Dosage”) = 200 RS.Update
      • Or Find desired record, Edit, & Update :
        • do while NOT RS.eof if RS(“ID”) = 7 then RS(“Dosage”) = 200 RS.Update else RS.MoveNext end if loop
  • 20. ASP Key Points (5)
    • Clean up (free server resources) when done:
      • Queries:
        • Patients.Close set Patients = nothing
      • Record Sets:
        • RS.Close set RS = nothing
      • The Connection:
        • conn.close set conn = nothing
  • 21. ASP Security
    • Apart from various Internet Information Services (IIS – Window’s Web service) security holes (for viruses and worms), security is quite good.
    • Use http s :// … if you want to protect content over the internet – this provides Secure Socket Layer (SSL) security
  • 22. ASP Resources
    • ITC-Training Workshops
      • ASP Introduction
    • Microsoft’s
      • ASP Guide
      • VBScript and JScript Language References
    • ITC-Desktop’s examples
    • WebMonkey’s tutorial
    • Beginning ASP Databases by Kauffman (Wrox)
    • Professional Active Server Pages 3.0 by Homer (Wrox)
  • 23. ColdFusion
    • Easy-to-learn Server-Side Scripting Language: CFML, or Cold Fusion Markup Language, is embedded in HTML code
    • CF code is enclosed in or by CF tags:
      • <CF tagname CF code >
      • <Cf tagname > CF Code </Cf tagname >
    • Documents must end in .cfm
    • ColdFusion is Case In sensitive
    • Example ( code , copy of database )
  • 24. ColdFusion Key Points (1)
    • All #variables# are enclosed in # signs
    • HTML output which includes of CF variables must be surrounded by CF output tags; e.g.:
      • <CFset height = “tall”> <CFoutput> The <B>#height#</B> boy fell. <CFoutput>
  • 25. ColdFusion Key Points (1)
    • Connect with database and run query simultaneously:
      • <CFQUERY Name=&quot;Patients&quot; dbtype=&quot;dynamic&quot; connectstring=&quot;#DBdriver# #DBfile#&quot;> SELECT ID, FirstName, LastName FROM Patients ORDER BY FirstName </CFQUERY>
    • Where the variables are defined beforehand:
      • <CFset Dbdriver = &quot;Driver={MICROSOFT ACCESS DRIVER (*.mdb)}; UID=admin; PWD=; dbq=&quot;>
      • <CFset Dbfile = &quot;f:webdatabase escompstudy.mdb&quot;>
  • 26. ColdFusion Key Points (2)
    • Access Query Results
      • <SELECT name=&quot;PatientID&quot;> <CFoutput QUERY=&quot;Patients&quot;> <OPTION value=#ID#>#FirstName# #LastName# </CFoutput> </SELECT>
    • Insert Data from a Form
      • If a HTML form submits variables to be inserted, do so directly using CFinsert:
        • <CFinsert tablename=&quot;Treatment&quot; dbtype=&quot;dynamic&quot; connectstring=&quot;#DBdriver# #DBfile#&quot;>
      • All variables in the form object (e.g. Form.var1) that match attributes in the table are inserted into the table automatically
  • 27. ColdFusion Key Points (3)
    • Insert Data using Cfquery (SQL):
      • <CFquery name=&quot;Treatment&quot; dbtype=&quot;dynamic&quot; connectstring=&quot;#DBdriver# #DBfile#&quot;> INSERT into Treatment VALUES (#PatientID#, #EventID#, Now(), #Dosage(mg)#, #Severity#, #Time#) </CFquery>
    • Other Data editing features also available
      • see Macromedia’s documentation webpage (find the ColdFusion Markup Language Reference and Quick Reference pdf files at the bottom of the documentation webpage)
  • 28. Cold Fusion Resources
    • ITC-Training Workshops
      • Cold Fusion Introduction
    • Allaire/Macromedia’s Documentation Web page
      • Developing CF Applications
      • CFML Reference
      • CFML Quick Reference
    • ITC-Desktop’s examples
    • WebMonkey’s tutorial
    • Security links page
    • Programming Cold Fusion by Brooks-Bilson (O’Reilly)
    • Cold Fusion 5 Web Applications Construction Kit (4 th Ed.) by Forta (Macromedia Press)
  • 29. Practical Extraction and Report Language ( Perl )
    • Ubiquitous
      • Originally designed to be a better general purpose tool than a Unix shell, it has grown and spread to be supported from Windows to Macintosh to VMS.
    • Powerful but Cryptic
    • Example ( code )
  • 30. Perl Key Points (1)
    • The file itself must end in “.cgi” or “.pl”
    • File must have “other” read and execute permission (chmod o+rx filename .pl)
    • First line must specify the location of the Perl engine (The DBI module will not work for “#!/usr/local/bin /perl[5]” – see below):
      • #!/uva/bin/perl -w
    • First printed line must be the following if you want its response to go to a browser:
      • print &quot;Content-type: text/html &quot;;
  • 31. Perl Key Points (2)
    • Modules
    • You *must* use the DBI module which allows you to interface with the database (see DBI link 1 & DBI link 2 )
      • use DBI;
    • You can & should also make use of the CGI module , esp. for parameter passing
      • use CGI;
  • 32. Perl Key Points (3)
    • Set the usual parameters:
      • my $hostname = &quot;dbm1.itc.virginia.edu&quot;; my $username = &quot;dld5s&quot;; # &quot;my&quot; defines a local variable my $password = “…&quot;; # fill in my $database = $username . &quot;_study&quot;; # = dld5s_study my $data_source = &quot;DBI:mysql:$database:$hostname&quot;;
    • Connect to the database:
      • my $dbh = DBI->connect($data_source, $username, $password) or die &quot;Can't connect to $data_source: $DBI::errstr &quot;;
  • 33. Perl Key Points (4)
    • Define the SQL statement and execute
      • my $SQL = &quot;SELECT FirstName, LastName, DOB, Gender FROM Patients WHERE Gender = '$Gender' ORDER BY FirstName DESC&quot;; my $sth = $dbh->prepare($SQL) or die &quot;Unable to prepare $SQL: dbh->errstr &quot;; $sth->execute or die &quot;Unable to execute query: $dbh->errstr &quot;;
    • Clean up
      • $sth->finish; $dbh->disconnect;
  • 34. Perl Security
    • Perl/MySQL can be made secure apart from one serious flaw as implemented at UVa:
      • Because web files must be readable by the world (unix permissions), anyone with an account on the server where you run the php code can see the code, including your MySQL $password!
      • A couple of exceptions to this flaw are as follows:
        • If you secure your server so that there are no other users on it
        • (It may ** be possible to compile Perl scripts into binary executables using perlcc. Then you must hide or remove your source code containing the MySQL password)
        • One other possible poor to fair workaround: use .htaccess to password protect your php directory (limited access)
      • See the passwords link , security links page
  • 35. Perl Resources
    • ITC-Training Workshops
      • Perl Programming Introduction
      • Perl Programming for the Web
    • Perl Documentation (UVa currently has 5.6, but 5.8 exists)
      • Overview , Built-in functions , Data types , Regular expressions , …
      • Modules : DBI(1) , CGI
    • WebMonkey’s Tutorial , etc.
    • MySQL and PERL for the Web by DuBois (New Riders)
    • Learning Perl by Schwartz & Christiansen (O’Reilly)
    • Programming Perl by Wall, Orwant, & Christiansen (O’Reilly)
    • Programming the Perl DBI: Database Programming with Perl by Descartes, Bunce, & Mui (Editor) (O’Reilly)
  • 36. PHP: Hypertext Preprocessor ( PHP )
    • HTML embedding scripting language (see the PHP online manual
    • When a browser calls a PHP document, the Server reads the PHP document and
      • Runs the PHP code
      • Returns the resulting HTML code to the browser
    • Example ( code )
  • 37. PHP Key Points (1)
    • Filename must end in .php or .phtml
    • File must have “other” read permission (chmod o+r filename .phtml)
    • PHP code enclosed in <?php PHP code ?> or <? PHP code ?>
    • Everything outside is HTML
    • Output is (generally) to a browser requiring standard HTML
  • 38. PHP Key Points (2)
    • Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions
    • Connect with MySQL RDBMS
      • mysql_connect($hostName, $userName, $password) or die(&quot;Unable to connect to host $hostName&quot;);
    • Connect with database
      • mysql_select_db($dbName) or die(&quot;Unable to select database $dbName&quot;);
  • 39. PHP Key Points (3)
    • Queries: Nearly all table interaction and management is done through queries:
    • Basic information searches
      • $SQL = &quot;SELECT FirstName, LastName, DOB, Gender FROM Patients WHERE Gender = '$Gender‘ ORDER BY FirstName DESC&quot;; $Patients = mysql_query($SQL);
    • Editing, adding, and deleting records and tables
      • $SQL = &quot;INSERT INTO Patients (FirstName, LastName) VALUES('$firstName', '$lastName')&quot;; $Patients = mysql_query($SQL);
  • 40. PHP Key Points (4)
    • Looping through and extracting results
      • $numPatients = mysql_numrows($Patients);
      • For ($I-0; $I<$numPatients; $I++) { $lastName = mysql_result($Patients, $I, “LastName”); … }
    • Cleaning up: close the database connection
      • mysql_close();
  • 41. PHP/MySQL Security
    • The same problems as PHP occur with Perl if you run it as a Perl or CGI script.
      • See the passwords link
  • 42. PHP Resources
    • ITC-Training Workshops
      • PHP and MySQL
    • PHP Documentation
    • ITC-Desktop’s examples
    • PHP’s Tutorial
    • WebMonkey’s Tutorial
    • PHP and MySQL Web Development by Welling & Thomson (SAMS)
    • Beginning PHP4 by Blan, Choi, et. al (Wrox)
  • 43. (Other) Books
    • Beginning ASP Databases by Kauffman (Wrox)
    • Professional Active Server Pages 3.0 by Homer (Wrox)
    • Programming Cold Fusion by Brooks-Bilson (O’reilly)
    • Cold Fusion 5 Web Applications Construction Kit (4 th Ed.) by Forta (Macromedia Press)
    • MySQL by DuBois (New Riders)
    • MySQL and PERL for the Web by DuBois (New Riders)
    • MySQL & mSQL byYarger, Reese, & King
    • PHP and MySQL Web Development by Welling & Thomson (SAMS)
    • Beginning PHP4 by Blan, Choi, et. al (Wrox)
    • Learning Perl by Schwartz & Christiansen (O’Reilly)
    • Programming Perl by Wall, Orwant, & Christiansen (O’Reilly)
    • Programming the Perl DBI: Database Programming with Perl by Descartes, Bunce, & Mui (Editor) (O’Reilly)
    • SQL-99 Complete, Really by Gulutzan & Pelzer (R&D Books)
  • 44. Java Server Pages
    • Script language like ASP, Cold Fusion, PHP
    • Write once for all platforms
  • 45. Java Key Points (1)
    • Download the MySQL driver from sourceforge .net
    • Java-MySQL examples
      • http://www.itc.virginia.edu/atg/techtalks/powerpoint/mysql/javaex.txt