Creating databases for web applications Library. New example: student database. Homework: Complete class example. Catch up on source postings. Do creation.

Slides:



Advertisements
Similar presentations
Access 2007 ® Use Databases How can Microsoft Access 2007 help you structure your database?
Advertisements

Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Keys, Referential Integrity and PHP One to Many on the Web.
1 Chapter 5 – Handling HTML Controls in Web Pages spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making.
U:/msu/course/cse/103 Day 23, Slide 1 Review of Day 22 What query did you use to search for an actor by name? –Return matches.
1 SYSTEMS DESIGN Pertemuan 13 s.d 20 Matakuliah: A0554/Analisa dan Perancangan Sistem Informasi Akuntansi Tahun: 2006.
Introduction to Structured Query Language (SQL)
Concepts of Database Management Sixth Edition
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
U NIT 4 F ILE U PLOAD. I. C REATE AN U PLOAD -F ILE F ORM - With PHP, it is possible to upload files to the server.To allow users to upload files from.
Creating Databases SELECT. UPDATE. Demonstrate projects. Classwork / Homework: Prepare to choose teams & projects.
1 Insert, Update and Delete Queries. 2 Return to you Address Book database. Insert a record.
Creating databases for web applications
Creating databases for web applications Walk before run? Songs with features example. Retrieve information from database. Recordsets. Arrays. Loops. Homework:
INTERNET APPLICATION DEVELOPMENT For More visit:
Introduction –All information systems create, read, update and delete data. This data is stored in files and databases. Files are collections of similar.
C H A P T E R 4 Designing Database E-Commerce Hassanin M. Al-Barhamtoshy
Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.
Creating Databases Uploading Files. Reading & writing files. Homework: Starting planning ‘original’ project.
Creating Databases for Web Applications Library diagrams Continue with diagrams for video clip archive and for (Flash) grid design. General and specific.
Dbwebsites 2.1 Making Database backed Websites Session 2 The SQL… Where do we put the data?
PHP meets MySQL.
Analyzing Data For Effective Decision Making Chapter 3.
ABC Insurance Co. Paul Barry Steve Randolph Jing Zhou CSC8490 Database Systems & File Management Dr. Goelman Villanova University August 2, 2004.
Creating Databases More SQL. Design. Original Project Assignment Homework: Post proposal. Continue with planning.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
Creating Databases for Web Applications Reprise: Systems design (diagrams) Flash to php Homework: Prepare for quiz.
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 databases for web applications Database datatypes. Creating database Homework: Create tables in database. Add records to database.
PHP+MySQL Integration. Connecting to databases One of the most common tasks when working with dynamic webpages is connecting to a database which holds.
Concepts of Database Management Seventh Edition
Robin Mullinix Systems Analyst GeorgiaFIRST Financials PeopleSoft Query: The Next Step.
Creating PHPs to Insert, Update, and Delete Data CS 320.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Creating Databases Local storage. join & split Classwork: show 1 table application. Share designs for oscars application. Adaptive select. Homework: [Catch.
Creating Databases for web applications [Complete presentations] More SQL Class time: discuss final projects. Do posting if you have not done it.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
CST336, Spring 2015 Week 8: PHP File Upload. PHP provides specific functions to handle binary data such as uploading a file into the server, storing it.
Using Flash with php Very quick introduction to Flash Homework: work on projects.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
Creating databases for web applications Report on using sources, getting examples working. Retrieve information from database. Recordsets. Arrays. Loops.
Creating Databases One-way encryption. Passwords. Security issues. Data normalization. Integrity and Robustness. Homework: Finalize teams & projects. Making.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Creating Databases for Web Applications 3-Tier. Design vs Function vs Content. More SQL. More php. Homework: work on final projects.
Lesson 4: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Set query.
Company LOGO In the Name of Allah,The Most Gracious, The Most Merciful King Khalid University College of Computer and Information System Web pages Development.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
Creating Databases for Web applications Making a table of table information. Reprise on database design. SQL. Classwork/Homework: Projects! Postings.
Unit 7 How to Upload Files. A very useful aspect of PHP is its ability to manage file uploads to your server. Before you can use PHP to manage your uploads,
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
PHP File Handling. Opening a file Fopen(filename,mode) Closing a file Fclose(filename)
Confirm teams. Review of diagrams. SELECT problems.
Creating Databases Local storage. join & split
Creating databases for web applications
Creating databases for web applications
Creating databases for web applications
Creating Databases More SQL. Design. Original Project Assignment
Databases and Information Management
Creating Databases SELECT. UPDATE. Demonstrate projects. Do not track.
Databases and Information Management
INFO/CSE 100, Spring 2006 Fluency in Information Technology
COMP 208/214/215/216 – Lecture 7 Documenting Design.
Presentation transcript:

Creating databases for web applications Library. New example: student database. Homework: Complete class example. Catch up on source postings. Do creation and simple entry and retrieval for a database.

Library? Show information (ERD) and process (DFD)

Simple example Students: name, gpa, department meyer/studentexample/showstudents.phphttp://socialsoftware.purchase.edu/jeanine. meyer/studentexample/showstudents.php meyer/studentexample/showdepartments. phphttp://socialsoftware.purchase.edu/jeanine. meyer/studentexample/showdepartments. php meyer/studentexample/enterstudent.htmlhttp://socialsoftware.purchase.edu/jeanine. meyer/studentexample/enterstudent.html

Storyboard createtable enterstudent.html enterstudent.php showstudents.php showdepartments.php

Note Plenty to add –improve look of enterstudent.html –provide better feedback –add edit student info function, probably based on displaying a list –add more display functions, such as top student in each department, all students with averages over a certain amount, ? –more information

create the one table Fields id name department GPA So what should the SQL and what should all the code be? Write it down.

<?php require("connectcode.php"); $tname = "students"; $fields = "sid INT NOT NULL AUTO_INCREMENT PRIMARY KEY, sname CHAR(30), sgpa FLOAT(5,4), sdept CHAR(30)"; $query = "DROP TABLE students"; mysqli_query($link,$query); $query = "CREATE TABLE $tname ($fields)"; if (mysqli_query($link,$query)) { print ("The table, $tname, was created successfully. \n"); } else { print ("The table, $tname, was not created. \n"); } mysqli_close($link); ?>

Adding a record to the students table The enterstudent.html file does not use php. It displays a form that invokes enterstudent.php using the action attribute on the form. Think about what the html file would look like….

enterstudent.html Input student Student Name Department GPA

Note The names of the input fields of the form do not have to be consistent with the names of the fields in the database table. Extra credit opportunity: Report on Ruby on Rails. This is an alternative to html and php that produces code that uses these connections. The php code does insert slashes to prevent problems with names such as O'Bama. … does check that gpa is a number. Could add a tighter check that it is a number between 0 and 5 (?). The 0 for the sid field is a placeholder. The stored sid will be the autoincremented value.

enterstudent.php <?php require("connectcode.php"); $sn =$_GET['sn']; $sn = ADDSLASHES($sn); $sd=$_GET['sd']; $sd = ADDSLASHES($sd); $sgpa = $_GET['sgpa']; if (!is_numeric($sgpa)) { print ("Bad GPA data."); } else { $query="INSERT INTO students VALUES ("; $query.="'0','$sn',$sgpa,'$sd')"; print ("query is $query. "); if (mysqli_query($link,$query)) { print ("Student record added successfully"); } Else { print ("failure to add student record "); } } mysqli_close($link); //this depends on db link ?>

Note Order of fields is important for the VALUES form of the INSERT statement. There is another form: INSERT INTO students SET … Extra credit: research and see what works.

showstudents.php List contents of students table <?php require("connectcode.php"); $query="SELECT * FROM students"; $result=mysqli_query($link, $query); print(" "); print(" Student Department GPA "); while ($row=mysqli_fetch_array($result)) { print(" "); print(" ".$row['sname']." "); print (" ".$row['sdept']." "); print (" ".$row['sgpa']." "); print (" "); } mysqli_close($link); ?>

Another enhancement What to do when the table gets big? Implement 'paging' Put in buttons, perhaps using an a tag with a query string giving the page value The SELECT statement has a LIMIT feature –SELECT …. LIMIT 1, 10 –SELECT …. LIMIT 11, 10 –$query = "SELECT ….. LIMIT ". $next. ", 10 " Opportunity for research.

showdepartments Aggregate functions –count –average –sum –… Use names (aliases) in the SELECT statement ORDER BY GROUP BY

from showdepartments.php <?php require("connectcode.php"); $query="SELECT sdept, AVG(sgpa) as a, COUNT(*) as c FROM students GROUP BY sdept ORDER BY a DESC"; $result=mysqli_query($link, $query); print(" "); print(" Department Average GPA COUNT "); while ($row=mysql_fetch_array($result)) { print(" "); print(" ".$row['sdept']." "); print (" ".$row['a']." "); print (" ".$row['c']." "); print (" "); } mysqli_close($link); ?>

Variation Impose condition on the GROUPed data meyer/studentexample/showbigdepartmen ts.phphttp://socialsoftware.purchase.edu/jeanine. meyer/studentexample/showbigdepartmen ts.php Change QUERY to $query="SELECT sdept, AVG(sgpa) as a, COUNT(*) as c FROM students GROUP BY sdept HAVING c>1 ORDER BY a DESC";

SELECT WHERE condition and JOIN conditions are done on individual records. HAVING condition is on GROUPed data. Look at my examples AND use sources.

Caution The word 'design' may refer to Design (plan, structure, organization, definition) of the database and the application The look of an application One of my examples: the content of the product being produced is the design of a grid using pre-defined units.

Systems design Focus on information –what is the information and how do [things] relate –Entity relationship diagramming is a tool –Information may exist already in the organization organizations may have products, perhaps customized, to hold their information includes dates, versions, owners, etc. Focus on function of application(s) –who does what –… using what information

System design slow down rush to implement [start] documentation Design and documentation may change as system is being built, deployed, refined…. Still, goal is to decrease bugs

ER diagram Database holds –Tables. Table represents one type of entity Row in table holds information on one example of the entity –Row in table made up of Attributes (aka fields) Lines connecting tables indicate occurrence of attribute in one table that points to a row in another table (or that table) –What is the pointer? The id of the row. This is called a foreign key. One mark of good design is robustness: ease of changing over time.

File upload What if the application requires users to upload files? –and asking them to use an ftp program not appropriate The ISP may not permit this. CTS put restrictions on us. Why?

fileupload1.html Get file name <form action="fileupload2.php" method="post" enctype="multipart/form-data"> Filename:

fileupload2.php <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < )) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: ". $_FILES["file"]["error"]. " "; } else

fileupload2.php, cont. { echo "Upload: ". $_FILES["file"]["name"]. " "; echo "Type: ". $_FILES["file"]["type"]. " "; echo "Size: ". ($_FILES["file"]["size"] / 1024). " Kb "; echo "Temp file: ". $_FILES["file"]["tmp_name"]. " "; if (file_exists($_FILES["file"]["name"])) { echo $_FILES["file"]["name"]. " already exists. "; } else { $target = "uploads/"; $target.= $_FILES["file"]["name"]; move_uploaded_file ($_FILES["file"]["tmp_name"],$target); echo "Stored as: ". $target; } } }

fileupload2.php else { echo "Invalid file"; } ?>

Classwork/Homework Application: database for movies Tables: movies, people_having_role_in_movie, people, nominations, ? What processes would you want? –what maintenance functions do you want to have? –what questions would you want to ask

JOINs Some questions require data from multiple tables. Tables can be connected by conditions, most typically connecting foreign keys with primary keys. SELECT …. FROM table1 as t JOIN table2 as s ON t.fid = s.fid –The fid field may be primary key in table1. It is referenced by a field in table2.

Multiple tables SELECT p.pname, n.award FROM people as p JOIN roles as r ON p.pid = r.pid JOIN nominations as n ON r.rid = n.rid WHERE n.award IN (“BEST LEAD ACTOR”, “BEST LEAD ACTRESS”, “BEST SUPPORTING ACTOR”, “BEST SUPPORTING ACTRESS”)

Tasks List all movies by name, ordered by date List all people by name with roles in a given movie, named $moviename List all directors (by name), with movie (by name) ordered by movie name List all movies by name in which someone was nominated for Best Lead Actor List all movies by name in which someone was nominated for an acting category –Best Lead Actor, Best Lead Actress, Best Supporting Actor, Best Supporting Actress

More List movie name, person name, award name ordered by movie name List movie name, number of people nominated, ordered from high to low –EXTRA CREDIT: figure out how not to count multiples for awards that have multiples (such as producer, technical awards List winners: movie name, person name, award

Research Some questions require consideration of absent records –What movies were nominated (had people nominated) for Best Movie but not Best Director –? Look up and study examples of LEFT JOINS

Classwork/homework Devise [more] SQL statements Keep experimenting with creating tables, simple html and php scripts for data entry and for display.