M.P. Johnson, DBMS, Stern/NYU, Spring 20061 C20.0046: Database Management Systems Lecture #16 M.P. Johnson Stern School of Business, NYU Spring, 2008.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
M.P. Johnson, DBMS, Stern/NYU, Sp20041 C : Database Management Systems Lecture #20 Matthew P. Johnson Stern School of Business, NYU Spring, 2004.
Copyright 2004 Monash University IMS5401 Web-based Systems Development Topic 2: Elements of the Web (g) Interactivity.
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #20 M.P. Johnson Stern School of Business, NYU Spring, 2005.
B.Sc. Multimedia ComputingMedia Technologies Database Technologies.
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #22 M.P. Johnson Stern School of Business, NYU Spring, 2005.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic Server Side Web Technologies: Part 2.
M.P. Johnson, DBMS, Stern/NYU, Sp20041 C : Database Management Systems Lecture #21 Matthew P. Johnson Stern School of Business, NYU Spring, 2004.
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #17 M.P. Johnson Stern School of Business, NYU Spring, 2008.
Python and Web Programming
Website Development with PHP and MySQL Introduction.
Guide To UNIX Using Linux Third Edition
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #21 M.P. Johnson Stern School of Business, NYU Spring, 2005.
1 Java Server Pages Can web pages be created specially for each user? What part does Java play?
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
PHP: Introduction By Trevor Adams.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
SJSU CS157B Dr. Lee1  2004 Jenny Mitchell Two Useful Tools You Can’t Live Without by Jenny Mitchell SJSU CS157B Section PHP and MySQL.
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
JAVASCRIPT HOW TO PROGRAM -2 DR. JOHN P. ABRAHAM UTPA.
1 Homework / Exam Exam 3 –Solutions Posted –Questions? HW8 due next class Final Exam –See posted schedule Websites on UNIX systems Course Evaluations.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
Server-side Scripting Powering the webs favourite services.
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
Lecture 14 – Web Security SFDV3011 – Advanced Web Development 1.
INTERNET APPLICATION DEVELOPMENT For More visit:
PHP TUTORIAL. HISTORY OF PHP  PHP as it's known today is actually the successor to a product named PHP/FI.  Created in 1994 by Rasmus Lerdorf, the very.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
2 1 Sending Data Using a Hyperlink CGI/Perl Programming By Diane Zak.
Introduction to Programming the WWW I CMSC Summer 2004 Lecture 6.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
Lecture # 6 Forms, Widgets and Event Handling. Today Questions: From notes/reading/life? Share Personal Web Page (if not too personal) 1.Introduce: How.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 7: HTTP and CGI Fundamentals of Web Programming.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Putting it all together Dynamic Data Base Access Norman White Stern School of Business.
Website Development with PHP and MySQL Saving Data.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
CS 4720 Dynamic Web Applications CS 4720 – Web & Mobile Systems.
Computational Boot Camp HTML Mike Schaffer. 8/23/2002 (MES) HTML What is HTML? HTML stands for HyperText Markup Language HTML is the language for publishing.
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) Instructor: Joseph DiVerdi,
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Introduction to JavaScript CS101 Introduction to Computing.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
1) PHP – Personal Home Page Scripting Language 2) JavaScript.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
: Information Retrieval อาจารย์ ธีภากรณ์ นฤมาณนลิณี
World Wide Web has been created to share the text document across the world. In static web pages the requesting user has no ability to interact with the.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
HTML III (Forms) Robin Burke ECT 270. Outline Where we are in this class Web applications HTML Forms Break Forms lab.
University of Kansas Department of Electrical Engineering and Computer Science Dr. Susan Gauch April 21, 2005 I T T C Introduction to Web Technologies.
2nd year Computer Science & Engineer
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
Introduction to Programming the WWW I
PHP / MySQL Introduction
Presentation transcript:

M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #16 M.P. Johnson Stern School of Business, NYU Spring, 2008

M.P. Johnson, DBMS, Stern/NYU, Spring Homework Project part 2 due Wed in class/by midnight Project part 3 posted soon…  Topic: populating your tables with data Later: Project part 5  Front-end

M.P. Johnson, DBMS, Stern/NYU, Spring Agenda: Programming for SQL Have now been exposed to:  Embedded SQL: Pro*C  Java JDBC All used; good to know about Most important for this course:  DB-conn from web scripting languages  PHP

M.P. Johnson, DBMS, Stern/NYU, Spring Goals: by next week Today: be able to post a hello-web PHP script in your i5 account Next week: Be able to write simple dynamic webpages in In PHP that 1. Take input from user 2. Execute SQL query 3. Display formatted results  Based on examples from class…

M.P. Johnson, DBMS, Stern/NYU, Spring New topic: web apps Goal: web front-end to database  Present dynamic content, on demand  Not canned (static) pages/not canned queries  (perhaps) modify DB on demand Naïve soln: static webpage & HTTP  index.html written, stored, put on server, displayed when it’s url is requested  HTTP is stateless (so?)  This doesn’t solve our problem

M.P. Johnson, DBMS, Stern/NYU, Spring Dynamic webpages Soln 1: upon url request 1. somehow decide to dynamically generate an html page (from scratch) 2. send back new html page to user  No html file exists on server, just created on demand  CGI/Perl, Java servlets, etc.

M.P. Johnson, DBMS, Stern/NYU, Spring New topic: CGI First, and still very popular method CGI: Common Gateway Interface  Not a programming language!  Just an interface (connection) between the webserver and an outside program “Webserver” = webserver software, e.g., Apache  Very simple basic idea: 1. user chooses an url 2.  webserver runs that url’s program, 3. sends back the program’s output

M.P. Johnson, DBMS, Stern/NYU, Spring On-the-fly content with CGI Program Client Server HTTP Request Data for program Generated HTML HTML Image from

M.P. Johnson, DBMS, Stern/NYU, Spring Using CGI CGI works with any prog./scripting lang. Really? Well, if things are set up right…

M.P. Johnson, DBMS, Stern/NYU, Spring CGI works… if the webserver machine can run program  pages/soho, not sales and if the user the webserver is running as (e.g. nobody) can can run your program and if the necessary jars/libraries are available and if nobody has permission to use them and if the necessary DB software is installed Plausible choices: Perl, Python, C, sh

M.P. Johnson, DBMS, Stern/NYU, Spring CGI admin Most webservers: CGI program/script must either 1. End in.cgi and/or 2. Reside in cgi-bin If an actual program, the cgi file is just the name of the executable: In a script, first (“shebang”) line says which interpreter to use: gcc -o myprog.cgi myproc.gcc #!/usr/local/bin/perl

M.P. Johnson, DBMS, Stern/NYU, Spring CGI input CGI programs must respond to input, two ways GET: string is part of the URL, following a ?: POST: string can be read by program from an environmental variable  Vars not visible to the browser user  Not automatically put in server log, etc.

M.P. Johnson, DBMS, Stern/NYU, Spring CGI summary One big advantage of CGI: not a language Existing command-line programs can be called from the web Web user can enter info Program output sent back as webpage Don’t want to start a new process for every user/pageview/roundtrip of your site?

M.P. Johnson, DBMS, Stern/NYU, Spring PHP-like scripting Program Client Server HTTP Request Data for program Generated HTML HTML Image from

M.P. Johnson, DBMS, Stern/NYU, Spring Dynamic webpages Original prob: need webpages to respond to user inputs Soln 2:  create a an html file embedded with special non- html code  upon url request, execute embedded code to generate more html/fill in the file  Send back the modified html page to user  An incomplete html page exists on server  Examples: PHP, JSPs, ASPs, etc.

M.P. Johnson, DBMS, Stern/NYU, Spring Review: dynamic webpages First option: for each request: run program, produce whole page, send back  CGI & some host language, Java Servlets, etc. Second option: create html page with missing parts; for each response, fill in the wholes and send back  Embedded scripting  PHP and others  PHP = Personal Home Page or = PHP Hypertext Processor – recursion

M.P. Johnson, DBMS, Stern/NYU, Spring Getting started Must set permissions in account on i5 Unix commands: ls, cd, pwn, cp, mv chmod command  Owner/group/all  Read/write/execute  Bitstrings…

M.P. Johnson, DBMS, Stern/NYU, Spring hello.php Q: What the difference between and \n? Hello from PHP Here comes the PHP part: \n"; ?> That's it! Hello from PHP Here comes the PHP part: \n"; ?> That's it!

M.P. Johnson, DBMS, Stern/NYU, Spring Script errors Script errors, w/ and w/o display_errors on:  Local dir must contain.htaccess:  Automatically load GET/POST params as vars   cp /home1/m/mpj3/public_html/php/.htaccess. php_flag display_errors on php_flag register_globals on php_flag display_errors on php_flag register_globals on

M.P. Johnson, DBMS, Stern/NYU, Spring PHP vars Names always start with $  <? $num1 = 58; $num2 = 67; print "First number ". $num1. " "; print "Second number ". $num2. " "; $total = $num1 + $num2; print "The sum is ". $total. " "; ?> <? $num1 = 58; $num2 = 67; print "First number ". $num1. " "; print "Second number ". $num2. " "; $total = $num1 + $num2; print "The sum is ". $total. " "; ?>

M.P. Johnson, DBMS, Stern/NYU, Spring Combining PHP and HTML <?php for($z=0;$z<=5;$z++) { ?> Iteration number <? } ?> <?php for($z=0;$z<=5;$z++) { ?> Iteration number <? } ?>

M.P. Johnson, DBMS, Stern/NYU, Spring More PHP syntax Somewhat C-like, somewhat Perl-like Case-sensitive Strings:  Concatenation op:.  Single, double quotes similar to Perl Comments:  # Unix shell-style  /* */ C-style  // C++-style Output:  echo(“hi there”);  print(“hi there”);  C’s printf

M.P. Johnson, DBMS, Stern/NYU, Spring PHP info PHP does not have both string and number ops like Perl Number ops treat (number) strings as numbers, regular strings as strings  Info function displays lots of server info: 

M.P. Johnson, DBMS, Stern/NYU, Spring New topic: HTML forms Interactive parts of HTML: forms Intuition for name: paper form  Fill in textboxes, check boxes or not, etc.  Turn it in (press button) HTML form  contains arb. # of INPUTs  Submits to somewhere (ACTION)  By GET or POST

M.P. Johnson, DBMS, Stern/NYU, Spring Form example On clicking Send, we go to the same page, but with “name=99&sumbit=OK” Enter a number: Enter a number:

M.P. Johnson, DBMS, Stern/NYU, Spring PHP and forms Obtain param a param, just prefix with $ (for now..) Goal: display text and button;  On submit, tell user what was entered Improve: also print, say, triple the input… if (isset($val)) print "You entered $val! "; if (isset($val)) print "You entered $val! ";

M.P. Johnson, DBMS, Stern/NYU, Spring PHP error-handling Many PHP scripts have lines of the form  some-statement OR die(“something happened”); What this means:  die exits with error message  PHP uses OR as and AND for bool operators  PHP supports boolean “short-circuiting” Boolean eval stops as fast as possible  Ftns often return 0/null/false for errors  if some-statement fails then we die

M.P. Johnson, DBMS, Stern/NYU, Spring New topic: PHP and databases PHP 5 has a JDBC-style DB interface But we’re using PHP 4.3.4… Special-purpose methods/libraries for MySQL, etc. Use these to obtain a connection, prepare and execute queries, etc.

M.P. Johnson, DBMS, Stern/NYU, Spring PHP & MySQL 1. Open a connection and open our DB: 2. Run query: $db = mysql_connect("mysql2.stern.nyu.edu:3306", user, pass); mysql_select_db("test", $db); $db = mysql_connect("mysql2.stern.nyu.edu:3306", user, pass); mysql_select_db("test", $db); $result = mysql_query($query,$db);

M.P. Johnson, DBMS, Stern/NYU, Spring PHP & MySQL 3. Extract next row of data from the results:  What this means: myrow is an array that can then be accessed  Other options, see code In general, to scroll through results, do: $myrow = mysql_fetch_row($result) while ($myrow = mysql_fetch_row($result)) # print row’s data while ($myrow = mysql_fetch_row($result)) # print row’s data

M.P. Johnson, DBMS, Stern/NYU, Spring Limit: PHP webpages that do something Semi-interesting PHP scripts:   Non-trivial but not huge: ~40 lines Works with two-column (a,b) table  Takes input from user  Returns rows whose a field contains value  If no/empty input, returns all rows Bad idea in general!

M.P. Johnson, DBMS, Stern/NYU, Spring lookup.php Two possible situations for running script: 1. Page opened for the first time 2. User entered parameter and pressed button Structure of file: 1. Print input box and button for next search  On button click, parameter is sent to this page’s url 2. (Try to) read input parameter 3. Open MySQL connection 4. Run query 5. Print results in a table 6. Disconnect from MySQL

M.P. Johnson, DBMS, Stern/NYU, Spring Higher-level structure As one page:  If we have params, display data based on them  Otherwise, prompt user for params, call self Could be:  Page 1: prompt for params, call page 2  Page 2: display data based on params In e.g.: always display data for convenience

M.P. Johnson, DBMS, Stern/NYU, Spring Insert/delete PHP example Similar to search example NB: form has two buttons

M.P. Johnson, DBMS, Stern/NYU, Spring Master-detail Perl/PHP example Idea: display list of regions;  When region clicked on, display its countries Mechanism: pass GET param in link, not with a FORM

M.P. Johnson, DBMS, Stern/NYU, Spring That’s all, folks! Q: Is this enough to get a job coding PHP? A: Probably not! But: a couple modified copies of lookup.php and/or cia.php + some HTML glue  fairly interesting site a couple modified copies of lookup.php and/or cia.php + some HTML glue  fairly interesting site

M.P. Johnson, DBMS, Stern/NYU, Spring For next time (in lab)… 1. Run/read these PHP scripts:       Go through at least one tutorial on PHP (on web/below) 3.Try posting a hello-web PHP script in your sales account Various others in dbms/php…dbms/php

M.P. Johnson, DBMS, Stern/NYU, Spring Tutorials on PHP Some material drawn from the following good tutorials: PHP introduction and examples:  Interactive PHP with database access:  Longer PHP/MySQL Tutorial from webmonkey:  Nice insert/update/delete example from webmonkey:  MySQL/Perl/PHP page from U-Wash: 