PHP Programming Part II and Database Design Session 3 INFM 718N Web-Enabled Databases.

Slides:



Advertisements
Similar presentations
Relational Databases Week 9 INFM 603.
Advertisements

Chapter 10: Designing Databases
What is a Database By: Cristian Dubon.
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.
LBSC 690 Session #7 Structured Information: Databases Jimmy Lin The iSchool University of Maryland Wednesday, October 15, 2008 This work is licensed under.
PHP (2) – Functions, Arrays, Databases, and sessions.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Debugging and Ajax Session 7 INFM 718N Web-Enabled Databases.
Database Management: Getting Data Together Chapter 14.
The Relational Database Model:
Database Design and MySQL
Structured Programming and UML Overview Session 2 LBSC 790 / INFM 718B Building the Human-Computer Interface.
MySQL and PHP Integration Session 6 INFM 718N Web-Enabled Databases.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
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
Modular Programming and Use Case Models Session 3 LBSC 790 / INFM 718B Building the Human-Computer Interface.
Week 1 INFM 718N Web-Enabled Databases The Big Picture.
Attribute databases. GIS Definition Diagram Output Query Results.
Relational Databases Week 7 LBSC 690 Information Technology.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
1 Relational Databases. 2 Find Databases here… 3 And here…
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Page 1 ISMT E-120 Desktop Applications for Managers Introduction to Microsoft Access.
Class 6 Data and Business MIS 2000 Updated: September 2012.
Relational Databases Week 13 LBSC 671 Creating Information Infrastructures.
Database Applications – Microsoft Access Lesson 2 Modifying a Table and Creating a Form 45 slides in presentation Accessibility check 9/14.
Databases From A to Boyce Codd. What is a database? It depends on your point of view. For Manovich, a database is a means of structuring information in.
Databases C HAPTER Chapter 10: Databases2 Databases and Structured Fields  A database is a collection of information –Typically stored as computer.
Copyright © 2003 by Prentice Hall Module 4 Database Management Systems 1.What is a database? Data hierarchy and data organization Field, record, file,
DAY 15: ACCESS CHAPTER 2 Larry Reaves October 7,
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Chapter 9 Designing Databases Modern Systems Analysis and Design Sixth Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich.
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Wednesday, March 5, 2014 Session 6: Relational.
PHP meets MySQL.
Databases Session 5 LIS 7008 Information Technologies LSU/SLIS.
MIS 301 Information Systems in Organizations Dave Salisbury ( )
Content Management Systems Week 14 LBSC 671 Creating Information Infrastructures.
Normalization (Codd, 1972) Practical Information For Real World Database Design.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Databases Week 5 LBSC 690 Information Technology.
1.NET Web Forms Business Forms © 2002 by Jerry Post.
Introduction to Databases Trisha Cummings. What is a database? A database is a tool for collecting and organizing information. Databases can store information.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
C6 Databases. 2 Traditional file environment Data Redundancy and Inconsistency: –Data redundancy: The presence of duplicate data in multiple data files.
Testing and Debugging Session 9 LBSC 790 / INFM 718B Building the Human-Computer Interface.
Creating PHPs to Insert, Update, and Delete Data CS 320.
PHP Week 8 INFM 603. Agenda Questions PHP Drupal Project Plan.
INFO1408 Database Design Concepts Week 15: Introduction to Database Management Systems.
Copyright 2006 Prentice-Hall, Inc. Essentials of Systems Analysis and Design Third Edition Joseph S. Valacich Joey F. George Jeffrey A. Hoffer Chapter.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 16 Using Relational Databases.
Database Basics BCIS 3680 Enterprise Programming.
1 A Very Brief Introduction to Relational Databases.
1 CS 430 Database Theory Winter 2005 Lecture 7: Designing a Database Logical Level.
1 10 Systems Analysis and Design in a Changing World, 2 nd Edition, Satzinger, Jackson, & Burd Chapter 10 Designing Databases.
Data Modeling Session 12 INST 301 Introduction to Information Science.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
1 Management Information Systems M Agung Ali Fikri, SE. MM.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Rationale Databases are an integral part of an organization. Aspiring Database Developers should be able to efficiently design and implement databases.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
XP Chapter 1 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Level 2 Objectives: Understanding and Creating Table.
Databases.
Designing and Debugging Batch and Interactive COBOL Programs
A Very Brief Introduction to Relational Databases
Week 6 LBSC 690 Information Technology
Presentation transcript:

PHP Programming Part II and Database Design Session 3 INFM 718N Web-Enabled Databases

Agenda PHP –Examples –Programming well Speed dating (20 minutes) Database design

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

Databases Database –Collection of data, organized to support access –Models some aspects of reality DataBase Management System (DBMS) –Software to create and access databases Relational Algebra –Special-purpose programming language

Database “Programming” Natural language –Goal is ease of use e.g., Show me the last names of students in CLIS –Ambiguity sometimes results in errors Structured Query Language (SQL) –Consistent, unambiguous interface to any DBMS –Simple command structure: e.g., SELECT Last name FROM Students WHERE Dept=CLIS –Useful standard for inter-process communications Visual programming (e.g., Microsoft Access) –Unambiguous, and easier to learn than SQL

E-R Diagrams Entities –Types Subtypes (disjoint / overlapping), aggregation –Attributes Mandatory / optional –Identifier Relationships –Cardinality –Existence –Degree

Normalization 1NF: –Atomic entries (Doug Oard) -> Doug, Oard –Unique columns (classes -> separate table) 2NF –No repeated data in multiple rows Ford, Taurus -> separate table 3NF –Nonkey dependent on primary key City depends on zip

Goals of “Normalization” Save space –Save each fact only once More rapid updates –Every fact only needs to be updated once More rapid search –Finding something once is good enough Avoid inconsistency –Changing data once changes it everywhere

Installing WAMP Run phpinfo.php –Error reporting on? MySQL configured? Create a database and user accounts (mysql) Run mysql_test.php –Connects OK?

Working with PHP Local vs. server-based display HTML as an indirect display mechanism “View Source” for debugging Procedural vs. Object-Oriented

Language Learning Learn some words Put those words together in simple ways Examine to broaden your understanding Create to deepen your mastery Repeat until fluent

Thinking About PHP Local vs. Web-server-based display HTML as an indirect display mechanism “View Source” for debugging Procedural perspective (vs. object-oriented)

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]; Arrays and loops work naturally together

Thinking about Arrays Naturally encodes an order among elements –$days = rksort($days); Natural data structure to use with a loop –Do the same thing to different data PHP unifies arrays and hashtables –Elements may be different types

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

Why Modularity? Limit complexity –Extent –Interaction –Abstraction Minimize duplication

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!”; }

Sources of Complexity Syntax –Learn to read past the syntax to see the ideas –Copy working examples to get the same effect Interaction of data and control structures –Structured programming Modularity

Some Things to Pay Attention To Syntax How layout helps reading How variables are named How strings are used How input is obtained How output is created Structured Programming How things are nested How arrays are used Modular Programming Functional decomposition How functions are invoked How arguments work How scope is managed How errors are handled How results are passed

Programming Skills Hierarchy Reusing code [run the book’s programs] Understanding patterns [read the book] Applying patterns [modify programs] Coding without patterns [programming] Recognizing new patterns

Best Practices Design before you build Focus your learning Program defensively Limit complexity Debug syntax from the top down

Rapid Prototyping + Waterfall Update Requirements Choose Functionality Build Prototype Initial Requirements Write Specification Create Software Write Test Plan

Focus Your Learning Find examples that work –Tutorials, articles, examples Cut them down to focus on what you need –Easiest to learn with throwaway programs Once it works, include it in your program –If it fails, you have a working example to look at

Defensive Programming Goal of software is to create desired output Programs transform input into output –Some inputs may yield undesired output Methods should enforce input assumptions –Guards against the user and the programmer! Everything should be done inside methods

Limiting Complexity Single errors are usually easy to fix –So avoid introducing multiple errors Start with something that works –Start with an existing program if possible –If starting from scratch, start small Add one new feature –Preferably isolated in its own method

Types of Errors Syntax errors –Detected at compile time Run time exceptions –Cause system-detected failures at run time Logic errors –Cause unanticipated behavior (detected by you!) Design errors –Fail to meet the need (detected by stakeholders)

Debugging Syntax Errors Focus on the first error message –Fix one thing at a time The line number is where it was detected –It may have been caused much earlier Understand the cause of “warnings” –They may give a clue about later errors If all else fails, comment out large code regions –If it compiles, the error is in the commented part

Run Time Exceptions Occur when you try to do the impossible –Use a null variable, divide by zero, … The cause is almost never where the error is –Why is the variable null? Exceptions often indicate a logic error –Find why it happened, not just a quick fix!

Debugging Run-Time Exceptions Run the program to get a stack trace –Where was this function called from? Print variable values before the failure Reason backwards to find the cause –Why do they have these values? If necessary, print some values further back

Logic Errors Evidenced by inappropriate behavior Can’t be automatically detected –“Inappropriate” is subjective Sometimes very hard to detect –Sometimes dependent on user behavior –Sometimes (apparently) random Cause can be hard to pin down

Debugging Logic Errors First, look where the bad data was created If that fails, print variables at key locations –if (DEBUG) echo “\$foobar = $foobar”; Examine output for unexpected patterns Once found, proceed as for run time errors –define (“DEBUG”, FALSE); to clean the output

Three Big Ideas Functional decomposition –Outside-in design High-level languages –Structured programming, object-oriented design Patterns –Design patterns, standard algorithms, code reuse

Structured Information FieldAn “atomic” unit of data –number, string, true/false, … RecordA collection of related fields Table A collection of related records –Each record is one row in the table –Each field is one column in the table Primary KeyThe field that identifies a record –Values of a primary key must be unique DatabaseA collection of tables

A Simple Example primary key

Another Example Which students are in which courses? What do we need to know about the students? –first name, last name, , department What do we need to know about the courses? –course ID, description, enrolled students, grades

A “Flat File” Solution Discussion Topic Why is this a bad approach?

Relational Algebra Tables represent “relations” –Course, course description –Name, address, department Named fields represent “attributes” Each row in the table is called a “tuple” –The order of the rows is not important Queries specify desired conditions –The DBMS then finds data that satisfies them

A Normalized Relational Database Student Table Department TableCourse Table Enrollment Table

Approaches to Normalization For simple problems –Start with “binary relationships” Pairs of fields that are related –Group together wherever possible –Add keys where necessary For more complicated problems –Entity relationship modeling

Example of Join Student TableDepartment Table “Joined” Table

Problems with Join Data modeling for join is complex Join are expensive to compute –Both in time and storage space But it is joins that make databases relational –Projection and restriction also used in flat files

Some Lingo “Primary Key” uniquely identifies a record –e.g. student ID in the student table “Compound” primary key –Synthesize a primary key with a combination of fields –e.g., Student ID + Course ID in the enrollment table “Foreign Key” is primary key in the other table –Note: it need not be unique in this table

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

Project New Table SELECT Student ID, Department

Restrict New Table WHERE Department ID = “HIST”

The SELECT Command Project chooses columns –Based on their label Restrict chooses rows –Based on their contents e.g. department ID = “HIST” These can be specified together –SELECT Student ID, Dept WHERE Dept = “History”

Restrict Operators Each SELECT contains a single WHERE Numeric comparison, =, <>, … e.g., grade<80 Boolean operations –e.g., Name = “John” AND Dept <> “HIST”

What are Requirements? Attributes –Appearance –Concepts (represented by data) Behavior –What it does –How you control it –How you observe the results

Who Sets the Requirements? People who need the task done (customers) People that will operate the system (users) People who use the system’s outputs People who provide the system’s inputs Whoever pays for it (requirements commissioner)

The Requirements Interview Focus the discussion on the task –Look for entities that are mentioned Discuss the system’s most important effects –Displays, reports, data storage –Learn where the system’s inputs come from –People, stored data, devices, … Note any data that is mentioned –Try to understand the structure of the data Shoot for the big picture, not every detail

The Project Plan One-page contract –Between developer and requirements commissioner Goal The problem to be solved ProductWhat you plan to deliver ScopeAvailable time and personnel RolesWhat you expect each other to do

First Things First Functionality Content Usability Security/Stability

One-Minute Paper What was the muddiest point in today’s class? Be brief! No names!