JavaScript and PHP Week 10 LBSC 690 Information Technology.

Slides:



Advertisements
Similar presentations
Relational Databases Week 9 INFM 603.
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?
Web Database Programming Connecting Database to Web.
PHP Week 11 INFM 603. Thinking About PHP Local vs. Web-server-based display HTML as an indirect display mechanism “View Source” for debugging –But not.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Web-Database Integration Week 8 LBSC 690 Information Technology.
LBSC 690 Session #7 Structured Information: Databases Jimmy Lin The iSchool University of Maryland Wednesday, October 15, 2008 This work is licensed under.
Programming Week 9 LBSC 690 Information Technology.
PHP (2) – Functions, Arrays, Databases, and sessions.
Debugging and Ajax Session 7 INFM 718N Web-Enabled Databases.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Database Design and MySQL
MySQL and PHP Integration Session 6 INFM 718N Web-Enabled Databases.
PHP Programming Session 2 INFM 718N Web-Enabled Databases.
Databases Week 7 LBSC 690 Information Technology.
Week 6 LBSC 690 Information Technology
Databases Week 6 LBSC 690 Information Technology.
LBSC 690: Session 7 Relational Databases
MySQL and Requirements Session 4 INFM 718N Web-Enabled Databases.
Week 1 INFM 718N Web-Enabled Databases The Big Picture.
Web-Database Integration
Introduction to Structured Query Language (SQL)
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
Relational Databases Week 13 LBSC 671 Creating Information Infrastructures.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
Session 5: Working with MySQL iNET Academy Open Source Web Development.
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
INTERNET APPLICATION DEVELOPMENT For More visit:
Classroom User Training June 29, 2005 Presented by:
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Wednesday, March 5, 2014 Session 6: Relational.
PHP meets MySQL.
Content Management Systems Week 14 LBSC 671 Creating Information Infrastructures.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
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.
1. Connecting database from PHP 2. Sending query 3. Fetching data 4. Persistent connections 5. Best practices.
Programming Week 11 LBSC 690 Information Technology.
Databases Week 5 LBSC 690 Information Technology.
Chapter 8 Collecting Data with Forms. Chapter 8 Lessons Introduction 1.Plan and create a form 2.Edit and format a form 3.Work with form objects 4.Test.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Relational Databases Week 11 LBSC 671 Creating Information Infrastructures.
Introduction to CS520/CS596_026 Lecture Two Gordon Tian Fall 2015.
CHAPTER 9 PHP AND MYSQL. A POSSIBLE SITE CONFIGURATION Application Folder index.php includes (folder)header.phpfooter.phpstyle.cssmodel (folder)mysqli_connect.php.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
Creating PHPs to Insert, Update, and Delete Data CS 320.
PHP Week 8 INFM 603. Agenda Questions PHP Drupal Project Plan.
Dynamic web content HTTP and HTML: Berners-Lee’s Basics.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
PHP getting data from a MySQL database. Replacing XML as data source with MySQL Previously we obtained the data about the training session from an XML.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Web Design and Development. World Wide Web  World Wide Web (WWW or W3), collection of globally distributed text and multimedia documents and files 
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
Relational Databases Week 7 INFM 603.
CSC 405: Web Application Engineering II8.1 Web programming using PHP What have we learnt? What have we learnt? Underlying technologies of database supported.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
Data Modeling Session 12 INST 301 Introduction to Information Science.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
Relational Databases (Part 2) Session 14 INST 301 Introduction to Information Science.
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 ©
Content Management Systems
Microsoft Access and SQL
Week 6 LBSC 690 Information Technology
Presentation transcript:

JavaScript and PHP Week 10 LBSC 690 Information Technology

Agenda Questions PHP Joomla! Mythical person-month Advanced Database topics

Some Details About Access Joins are automatic if field names are same –Otherwise, drag a line between the fields Sort order is easy to specify –Use the menu Queries form the basis for reports –Reports give good control over layout –Use the report wizard - the formats are complex Forms manage input better than raw tables –Invalid data can be identified when input –Graphics can be incorporated

Programming Tips Attention to detail! –Careful where you place that comma, semi-colon, etc. Write a little bit of code at a time –Add some functionality, make sure it works, move on –Don’t try to write a large program all at once Debug by viewing the “state” of your program –Print values of variables using document.write –Is the value what you expected?

JavaScript Resources Google “javascript” –Tutorials: to learn to write programs –Code: to do things you want to do Engineering and Physical Sciences Library

Ways of Generating Web Pages Static: Written in a markup language –HTML, XML Dynamic: Generated using a program –Common Gateway Interface [Perl] (.cgi) –Java servlets Dynamic: Generated from a database –Cold Fusion (.cfm) –PHP (.php)

Why Database-Generated Pages? Remote access to a database –Client does not need the database software Serve rapidly changing information –e.g., Airline reservation systems Provide multiple “access points” –By subject, by date, by author, … Record user responses in the database

Issues to Consider Benefits –Multiple views –Data reuse –Scalable –Access control Costs –Formal modeling –Complex (learn, design, implement, debug) –Brittle (relies on multiple communicating servers) –Not crawlable

Downside Brittle –Depends on multiple servers Complex –Learning, design, implementation, debugging Formally modeled

Three Ways to Serve Data Web Browser Cold Fusion Server Microsoft Access DBMS Microsoft Web Server.mdb PHP-enabled Web Server mysql DBMS mysql database

Microsoft “Data Access Pages” Displays database content on Web pages –Not very useful for changing database content Drag-and-drop design in Microsoft Access –“Reports” are designed for printing –“Pages” are designed for the Web Requirements: –Microsoft Web Server (not Apache) –IE 5 or higher Web browser (not Firefox) –“Office Web Components” on client machine IE 7 fails gracelessly without them!

Data Access Page Example Design View: Web Page:

Database Server-side Programming Interchange Language Client-side Programming Web Browser Client Hardware Server Hardware (PC, Unix) (MySQL) (PHP) (HTML, XML) (JavaScript) (IE, Firefox) (PC) Business rules Interaction Design Interface Design Relational normalization Structured programming Software patterns Object-oriented design Functional decomposition

PHP Programming Environments You need three systems on the same server: –PHP (programming language) –MySQL (DBMS) –Apache (Web server) XAMPP Server –Includes GUI tools OTAL (Sun Unix) supports Web deployment –Requires a text editor (e.g., emacs) or FTP

Making PHP HTML stuff <?php PHP stuff ?> HTML stuff stuff---/xxxxx.php

Download and install XAMPP – –Check to install Apache and MySQL as services –Check the Web server at Download and install Joomla! – –Unzip to c:\xampp\htdocs\joomla15 –Configure it at Host Name: localhost User Name: root Database Name: joomla15 DO NOT install sample data –Delete c:\xampp\htdocs\joomla15\installation

Connecting PHP to MySQL On XAMPP: $dbc=mysql_connect (‘localhost’, ‘userid’, ‘password’); On OTAL: $dbc=mysql_connect(‘:/export/software/otal/mysql/run/mysqld.sock’, ‘userid’, ‘password’);

Create a MySQL Database “root” user creates database + grants permissions –Using the XAMPP console (or mysql –u root –p) root has no initial password; just hit when asked –By the system administrator on OTAL (otal.umd.edu) CREATE DATABASE project; GRANT SELECT, INSERT, UPDATE, DELETE, INDEX, ALTER, CREATE, DROP ON project.* TO IDENTIFIED BY ‘bar’; FLUSH PRIVILEGES; Start mysql –MySQL console for XAMPP, ssh for OTAL mysql –u foo –p bar Connect to your database USE project;

Creating Tables CREATE TABLE contacts ( ckeyMEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT, idMEDIUMINT UNSIGNED NOT NULL, ctypeSMALLINT UNSIGNED NOT NULL, cstringVARCHAR(40) NOT NULL, FOREIGN KEY (id) REFERENCES persons(id) ON DELETE CASCADE, FOREIGN KEY (ctype) REFERENCES ctlabels(ctype) ON DELETE RESTRICT, PRIMARY KEY (ckey) ) ENGINE=INNODB;  To delete: DROP TABLE contacts;

Populating Tables INSERT INTO ctlabels (string) VALUES ('primary '), ('alternate '), ('home phone'), ('cell phone'), ('work phone'), ('AOL IM'), ('Yahoo Chat'), ('MSN Messenger'), (‘other’);  To empty a table: DELETE FROM ctlabels;

“Looking Around” in MySQL SHOW DATABASES; SHOW TABLES; DESCRIBE tablename; SELECT * FROM tablename;

Structured Query Language DESCRIBE Flight;

Structured Query Language SELECT * FROM Flight;

Structured Query Language SELECT Company.CompanyName, Company.CompanyPhone, Flight.Origin, Flight.DepartureTime FROM Flight,Company WHERE Flight.CompanyName=Company.CompanyName AND Flight.AvailableSeats>3;

Statements in PHP Sequential {…; …;…;} Semicolons are required at the end of every statement Conditional if (3==i) {…} else {…} Loop for ($i=0; $i<10; $i++) {…} while ($row=mysql_fetch_array(…)) {…} foreach ($array as $key => $value) {…} Braces are optional around a single statement

Variables Name starts with a $ –Case sensitive (assume everything could be!) Hold a value –Number (integer, float) –String (double quotes, \ escape character) –TRUE, FLASE –NULL Need not be declared (automatically “cast”)

Operators in PHP Arithmetic operators + - * / Logical operators = > && || ! String operator.

Arrays in PHP A set of key-element pairs $days = array(“Jan”->31, “Feb”=>28, …); $months = explode(“/”, “Jan/Feb/Mar/…/Dec”); $_POST Each element is accessed by the key –{$days[“Jan”]} –$months[0];

Functions in PHP Declaration function multiply($a, $b=3){return $a*$b;} Invoking a method $b = multiply($b, 7); All variables in a function have only local scope Unless declared as global in the function

Using PHP with (X)HTML Forms ”, size=30 /> Yes No if (isset($_POST[“submitted”])) { echo “Your address is $ .”; } else { echo “Error: page reached without proper form submission!”; }

<?php # Script mysql_connect.php // Set the database access information as constants. DEFINE ('DB_USER', 'tester'); DEFINE ('DB_PASSWORD', 'tester'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'sitename'); // Make the connection. $dbc (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: '. mysql_error() ); // Select the (DB_NAME) OR die ('Could not select the database: '. mysql_error() ); // Create a function for escaping the data. function escape_data ($data) { // Address Magic Quotes. if (ini_get('magic_quotes_gpc')) { $data = stripslashes($data); } // Check for mysql_real_escape_string() support. if (function_exists('mysql_real_escape_string')) { global $dbc; // Need the connection. $data = mysql_real_escape_string (trim($data), $dbc); } else { $data = mysql_escape_string (trim($data)); } // Return the escaped value. return $data; } // End of function. ?>

<?php # login.php // Send NOTHING to the Web browser prior to the session_start() line! // Check if the form has been submitted. if (isset($_POST['submitted'])) { require_once ('../mysql_connect.php'); // Connect to the db. $errors = array(); // Initialize error array. // Check for an address. if (empty($_POST[' '])) { $errors[] = 'You forgot to enter your address.'; } else { $e = escape_data($_POST[' ']); } // Check for a password. if (empty($_POST['password'])) { $errors[] = 'You forgot to enter your password.'; } else { $p = escape_data($_POST['password']); }

if (empty($errors)) { // If everything's OK. /* Retrieve the user_id and first_name for that /password combination. */ $query = "SELECT user_id, first_name FROM users WHERE ='$e' AND password=SHA('$p')"; $result ($query); // Run the query. $row = mysql_fetch_array ($result, MYSQL_NUM); // Return a record, if applicable. if ($row) { // A record was pulled from the database. // Set the session data & redirect. session_name ('YourVisitID'); session_start(); $_SESSION['user_id'] = $row[0]; $_SESSION['first_name'] = $row[1]; $_SESSION['agent'] = md5($_SERVER['HTTP_USER_AGENT']); // Redirect the user to the loggedin.php page. // Start defining the URL. $url = ' $_SERVER['HTTP_HOST']. dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. $url.= '/loggedin.php'; header("Location: $url"); exit(); // Quit the script. } else { // No record matched the query. $errors[] = 'The address and password entered do not match those on file.'; // Public message. $errors[] = mysql_error(). ' Query: '. $query; // Debugging message. } } // End of if (empty($errors)) IF. mysql_close(); // Close the database connection. } else { // Form has not been submitted. $errors = NULL; } // End of the main Submit conditional.

// Begin the page now. $page_title = 'Login'; include ('./includes/header.html'); if (!empty($errors)) { // Print any error messages. echo ' Error! The following error(s) occurred: '; foreach ($errors as $msg) { // Print each error. echo " - $msg \n"; } echo ' Please try again. '; } // Create the form. ?> Login Address: Password: <?php include ('./includes/footer.html'); ?>

Configuring Joomla! Major divisions –Sections –Categories Content –Articles –Links –Contact Navigation –Menus –Search

Discussion Point: Mythical Person-Month Why is software development different from manufacturing car? If it would take one person three months, why does it take four people SIX months?

Estimating Completion Time Rules of thumb –1/3 specification –1/6 coding –1/2 test planning, testing, and fixing! Add time for coding to learn as you go, but don’t take time away from the other parts! –Reread the section on “gutless estimating” if you are tempted

Database Server-side Programming Interchange Language Client-side Programming Web Browser Client Hardware Server Hardware (PC, Unix) (MySQL) (PHP) (HTML, XML) (JavaScript) (IE, Firefox) (PC) Business rules Interaction Design Interface Design Relational normalization Structured programming Software patterns Object-oriented design Functional decomposition

Ajax Applications Google Maps – Google Suggest – Sajax Tables – Sajax –

Trading People and Months is Hard Sequential constraints Communication Training

Databases in the Real World Some typical database applications: –Banking (e.g., saving/checking accounts) –Trading (e.g., stocks) –Airline reservations Characteristics: –Lots of data –Lots of concurrent access –Must have fast access –“Mission critical”

Source: Technology Review (July/August, 2008) Database layer: 800 eight-core Linux servers running MySQL (40 TB user data) Caching servers: 15 million requests per second, 95% handled by memcache (15 TB of RAM)

Database Integrity Registrar database must be internally consistent –Enrolled students must have an entry in student table –Courses must have a name What happens: –When a student withdraws from the university? –When a course is taken off the books?

Integrity Constraints Conditions that must always be true –Specified when the database is designed –Checked when the database is modified RDBMS ensures integrity constraints are respected –So database contents remain faithful to real world –Helps avoid data entry errors

Referential Integrity Foreign key values must exist in other table –If not, those records cannot be joined Can be enforced when data is added –Associate a primary key with each foreign key Helps avoid erroneous data –Only need to ensure data quality for primary keys

Concurrency Thought experiment: You and your project partner are editing the same file… –Scenario 1: you both save it at the same time –Scenario 2: you save first, but before it’s done saving, your partner saves Whose changes survive? A) Yours B) Partner’s C) neither D) both E) ???

Concurrency Example Possible actions on a checking account –Deposit check (read balance, write new balance) –Cash check (read balance, write new balance) Scenario: –Current balance: $500 –You try to deposit a $50 check and someone tries to cash a $100 check at the same time –Possible sequences: (what happens in each case?) Deposit: read balance Deposit: write balance Cash: read balance Cash: write balance Deposit: read balance Cash: read balance Cash: write balance Deposit: write balance Deposit: read balance Cash: read balance Deposit: write balance Cash: write balance

Database Transactions Transaction: sequence of grouped database actions –e.g., transfer $500 from checking to savings “ACID” properties –Atomicity All-or-nothing –Consistency Each transaction must take the DB between consistent states. –Isolation: Concurrent transactions must appear to run in isolation –Durability Results of transactions must survive even if systems crash

Making Transactions Idea: keep a log (history) of all actions carried out while executing transactions –Before a change is made to the database, the corresponding log entry is forced to a safe location Recovering from a crash: –Effects of partially executed transactions are undone –Effects of committed transactions are redone the log

Before You Go On a sheet of paper, answer the following (ungraded) question (no names, please): What was the muddiest point in today’s class?