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

Slides:



Advertisements
Similar presentations
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?
Advertisements

Web Database Programming Connecting Database to Web.
CGI Programming.
CIS101 Introduction to Computing Week 08. Agenda Your questions JavaScript text Resume project HTML Project Six This week online Next class.
Chapter 31 Basic Form-Processing Techniques JavaServer Pages By Xue Bai.
M.P. Johnson, DBMS, Stern/NYU, Sp20041 C : Database Management Systems Lecture #20 Matthew P. Johnson Stern School of Business, NYU Spring, 2004.
CPSC 203 Introduction to Computers Tutorial 59 & 64 By Jie (Jeff) Gao.
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #20 M.P. Johnson Stern School of Business, NYU Spring, 2005.
PHP (2) – Functions, Arrays, Databases, and sessions.
M.P. Johnson, DBMS, Stern/NYU, Sp20041 C : Database Management Systems Lecture #18 Matthew P. Johnson Stern School of Business, NYU Spring, 2004.
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #19 M.P. Johnson Stern School of Business, NYU Spring, 2008.
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #22 M.P. Johnson Stern School of Business, NYU Spring, 2005.
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 #21 M.P. Johnson Stern School of Business, NYU Spring, 2008.
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #21 M.P. Johnson Stern School of Business, NYU Spring, 2005.
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #16 M.P. Johnson Stern School of Business, NYU Spring, 2008.
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
PHP and SQL Server: Queries IST2101. Project Report 4 SQL Queries Due Sunday, 4/5 at 11:59pm Instructions on how to access team webspace and SQL database.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Dataface API Essentials Steve Hannah Web Lite Solutions Corp.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
JavaScript Form Validation
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
Server-side Scripting Powering the webs favourite services.
Lecture 7 Interaction. Topics Implementing data flows An internet solution Transactions in MySQL 4-tier systems – business rule/presentation separation.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
PHP meets MySQL.
Lecture # 6 Forms, Widgets and Event Handling. Today Questions: From notes/reading/life? Share Personal Web Page (if not too personal) 1.Introduce: How.
Introduction to SEQUEL. What is SEQUEL? Acronym for Structural English Query Language Acronym for Structural English Query Language Standard language.
2 Copyright © 2004, Oracle. All rights reserved. Running a Forms Developer Application.
JavaScript – Quiz #9 Lecture Code:
Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Putting it all together Dynamic Data Base Access Norman White Stern School of Business.
1cs Intersection of Concurrent Accesses A fundamental property of Web sites: Concurrent accesses by multiple users Concurrent accesses intersect.
Website Development with PHP and MySQL Saving Data.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
Creating PHPs to Insert, Update, and Delete Data CS 320.
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Topics Sending an Multipart message Storing images Getting confirmation Session tracking using PHP Graphics Input Validators Cookies.
BIT 286: Web Applications Lecture 10 : Thursday, February 5, 2015 ASP.Net Form Submission.
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.
WWW: an Internet application Bill Chu. © Bei-Tseng Chu Aug 2000 WWW Web and HTTP WWW web is an interconnected information servers each server maintains.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming –TextField Action Listeners, JEditorPane action listeners, HTML in a JEditorPane,
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 1: Introduction to IS2803 Rob Gleasure
Chapter 12© copyright Janson Industries Java Server Faces ▮ Explain the JSF framework ▮ SDO (service data objects) ▮ Facelets ▮ Pagecode classes.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
PHP Form Processing * referenced from
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.
2 Copyright © 2004, Oracle. All rights reserved. Running a Forms Developer Application.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
PHP and SQL Server: Connection IST 210: Organization of Data IST2101.
Running a Forms Developer Application
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
Database application MySQL Database and PhpMyAdmin
PHP / MySQL Introduction
ISC440: Web Programming 2 Server-side Scripting PHP 3
Presentation transcript:

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

M.P. Johnson, DBMS, Stern/NYU, Spring Agenda Project part 2 due today Project part 3 posted soon (Thurs?)…  Topic: populating your tables with data Today:  Html/php/mysql  Bulk loader  Transactions?  Etc.?

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 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 Obtaining my examples After logging into sales: Or getting examples directly from the web: $ cd public_html $ cp ~mjohnson/public_html/dbms/php/.htaccess. $ cp ~mjohnson/public_html/dbms/php/hello.php. $ emacs hello.php $ pico hello.php $ cd public_html $ cp ~mjohnson/public_html/dbms/php/.htaccess. $ cp ~mjohnson/public_html/dbms/php/hello.php. $ emacs hello.php $ pico hello.php $ cd public_html $ wget $ wget $ emacs hello.php $ pico hello.php $ cd public_html $ wget $ wget $ emacs hello.php $ pico hello.php

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 All 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: 

M.P. Johnson, DBMS, Stern/NYU, Spring Advice for use of novel languages 1. Rerun often  Don’t write the whole thing and then try to run 2. Use frequent prints to be sure of var vals (While debugging) 3. When stuck, picture continuum from your current program to some other program  other prog. works but doesn’t do what you want  change either/both, step by step, until they meet in the middle 4. Google is your friend Search for error messages, situations

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 New topic: the bulk loader To insert data, can insert rows one at a time with INSERT INTO VALUES(<>) If data is in/can be computed from other tables, can use  INSERT INTO SELECT … Often, have text file of data MySQL’s bulk loader will parse file and insert all into the database

M.P. Johnson, DBMS, Stern/NYU, Spring Running the bulk loader The bulk loader is a command-line program mysqlimport, separate from SQL*Plus: At cmd line, specify:  user/pass (pass is optional here)  Host  Database  Input file / table name i5% mysqlimport -umy-NetID -p --local my-db imptest.txt

M.P. Johnson, DBMS, Stern/NYU, Spring IMPORT DATA command Can also load data while inside mysql: Does not work without LOCAL  Means: reading from client (your directory), not server mysql> LOAD DATA LOCAL INFILE 'imptest.txt' INTO TABLE imptest;

M.P. Johnson, DBMS, Stern/NYU, Spring For more info & example If you want, you can  Use a different field separator  Reorder the fields  Import date values For more info, see the webpages:   Example currently here:  

M.P. Johnson, DBMS, Stern/NYU, Spring For rest tonight: group quiz (not graded) 1. Import impdata.txt into a table in your account  Submit a copy of select * from impdata 2. Post a (working) Hello, PHP file to your account  Submit url 3. Post and modify (in some interesting way) one of my other sample PHP pages in /php to your account/php  Submit url and an explanation of what you changed

M.P. Johnson, DBMS, Stern/NYU, Spring New-old topic: Transactions So far, have simply issued commands  Ignored xacts Recall, though: an xact is an operation/set of ops executed atomically  In one instant ACID test:  Xacts are atomic  Each xact (not each statement) must leave the DB consistent

M.P. Johnson, DBMS, Stern/NYU, Spring Default xact behavior (in Oracle) An xact begins upon login By default, xact lasts until logoff  Except for DDL statements  They automatically commit Examples with two views of tbl…  But with TYPE=innodb !  mysql> set autocommit = 0

M.P. Johnson, DBMS, Stern/NYU, Spring Direct xact instructions At any point, may explicitly COMMIT:  SQL> COMMIT;  Saves all statements entered up to now  Begins new xact Conversely, can ROLLBACK  SQL> ROLLBACK;  Cancels all statements entered since start of xact Example: delete from emp; or delete junk;

M.P. Johnson, DBMS, Stern/NYU, Spring Direct xact instructions Remember, DDL statements are auto- committed  They cannot be rollbacked Examples: Q: Why doesn’t rollback “work”? drop table junk; rollback; drop table junk; rollback; truncate table junk; rollback; truncate table junk; rollback;

M.P. Johnson, DBMS, Stern/NYU, Spring Savepoints (in Oracle?) Xacts are atomic Can rollback to beginning of current xact But might want to rollback only part way Make 10 changes, make one bad change Want to: roll back to before last change Don’t have Word-like multiple undo  But do have savepoints

M.P. Johnson, DBMS, Stern/NYU, Spring Savepoints Create a savepoint: emp example: --changes SAVEPOINT sp1; --changes SAVEPOINT sp2; --changes SAVEPOINT sp3 --changes ROLLBACK TO SAVEPOINT sp2; ROLLBACK TO SAVEPOINT sp1; --changes SAVEPOINT sp1; --changes SAVEPOINT sp2; --changes SAVEPOINT sp3 --changes ROLLBACK TO SAVEPOINT sp2; ROLLBACK TO SAVEPOINT sp1; SAVEPOINT savept_name; Can skip savepoints But can ROLLBACK only backwards Can ROLLBACK only to last COMMIT

M.P. Johnson, DBMS, Stern/NYU, Spring AUTOCOMMIT (in Oracle?) Finally, can turn AUTOCOMMIT on:  SQL> SET AUTOCOMMIT ON;  Can put this in your config file  Can specify through JDBC, etc. Then each statement is auto-committed as its own xact  Not just DDL statements

M.P. Johnson, DBMS, Stern/NYU, Spring Etc?