Dbwebsites 2.1 Making Database backed Websites Session 2 The SQL… Where do we put the data?

Slides:



Advertisements
Similar presentations
PHP II Interacting with Database Data. The whole idea of a database-driven website is to enable the content of the site to reside in a database, and to.
Advertisements

2010/11 : [1]Building Web Applications using MySQL and PHP (W1)MySQL Recap.
Faculty of Sciences and Social Sciences HOPE PHP & MySQL Stewart Blakeway FML 213
CSE 190: Internet E-Commerce Lecture 10: Data Tier.
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
Attribute databases. GIS Definition Diagram Output Query Results.
MIS2502: Data Analytics MySQL and SQL Workbench David Schuff
Structured Query Language SQL: An Introduction. SQL (Pronounced S.Q.L) The standard user and application program interface to a relational database is.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial Password: UWPstudent Password is case sensitive.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
MySQL Dr. Hsiang-Fu Yu National Taipei University of Education
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
INTERNET APPLICATION DEVELOPMENT For More visit:
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
MySQL + PHP.  Introduction Before you actually start building your database scripts, you must have a database to place information into and read it from.
Introduction to SQL Steve Perry
Simple Database.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
MySQL. MySQL is a Relational Database Management System (RDBMS) that runs as a server providing multiuser access to a number of databases. A third party.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”
Introduction to MySQL Lab no. 10 Advance Database Management System.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
Introduction to Internet Databases MySQL Database System Database Systems.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
CSC 2720 Building Web Applications Database and SQL.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
Database and mySQL Week 07 Dynamic Web TCNJ Jean Chu.
Database Fred Durao What is a database? A database is any organized collection of data. Some examples of databases you may encounter in.
M1G Introduction to Database Development 2. Creating a Database.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
Most information comes from Chapter 3, MySQL Tutorial: 1 MySQL: Part.
What’s a database? Data stored in a structured format that lends itself to easy manipulation and recall.
Visual Programing SQL Overview Section 1.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Database Basics BCIS 3680 Enterprise Programming.
SQL has several parts: Major ones: DDL – Data Definition Language {Defining, Deleting, Modifying relation schemas} DML – Data Manipulation Language {Inserting,
Task #1 Create a relational database on computers in computer classroom 308, using MySQL server and any client. Create the same database, using MS Access.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
What is MySQL? MySQL is a relational database management system (RDBMS) based on SQL (Structured Query Language). First released in January, Many.
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
1 MySQL and SQL. 2 Topics  Introducing Relational Databases  Terminology  Managing Databases MySQL and SQL.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 1: Introduction to IS2803 Rob Gleasure
Connecting (relating) Data Tables to get Custom Records (Queries) Database Basics.
There are two types of MySQL instructions (Data Definition Language) DDL: Create database, create table, alter table,,,. (Data Manipulation Language) DML.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Introduction to MySQL Ullman Chapter 4. Introduction MySQL most popular open-source database application Is commonly used with PHP We will learn basics.
Web Application Design. Data –What data is available? –How do we store it or how is it stored in the DB? Schema Data types Etc. –Where is the data?
Working with MySQL A290/A590, Fall /07/2014.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
Programming for the Web MySQL Command Line Using PHP with MySQL Dónal Mulligan BSc MA
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.
Lecture 1.21 SQL Introduction Steven Jones, Genome Sciences Centre.
3 A Guide to MySQL.
CS320 Web and Internet Programming SQL and MySQL
Unix System Administration
Database application MySQL Database and PhpMyAdmin
ISC440: Web Programming 2 Server-side Scripting PHP 3
PHP and MySQL.
CS3220 Web and Internet Programming SQL and MySQL
MySQL Database System Installation Overview SQL summary
CS3220 Web and Internet Programming SQL and MySQL
MySQL Database System Installation Overview SQL summary
CS4540 Special Topics in Web Development SQL and MS SQL
Presentation transcript:

dbwebsites 2.1 Making Database backed Websites Session 2 The SQL… Where do we put the data?

dbwebsites 2.2 How do databases work? Were going to look at systems known as Relational Databases. There are other more modern systems, but websites almost exclusively use relational systems. You may hear the terms DBMS and RDBMS, which stand for Database Management System and Relational Database Management System respectively.

dbwebsites 2.3 How do databases work? An DBMS is a server which is responsible for managing one or more databases. Database clients can connect to the server to extract data from the DB or insert data into the DB. For a website to use a database it needs a database client which it can use to extract data from the database, and use it to generate web pages. This is built into PHP, which will be covered in the last session.

dbwebsites 2.4 How do databases work? One DBMS can manage many databases. Each database contains a number of tables. Tables have rows of data. Each row is a complete record. Each column in the table can contain a certain type of data element, eg numbers, text, dates, etc. First Name Char(20) Surname Char(20) Human Enum(yes,no) Age Int Phone Char(15) Char(70) PeterBagnallYes

dbwebsites 2.5 Important Data Types BOOLEAN INT(precision) FLOAT(precision) DATE, DATETIME, TIMESTAMP[(M)], TIME, YEAR[(2|4)] CHAR(M) VARCHAR(M) BLOB TEXT ENUM('value1','value2',...), SET('value1','value2',...)

dbwebsites 2.6 Why Relational? Data in different tables can be related Example: A person lives at an address. Several people may live at the same address. By joining the people table and address tables together you can answer “Where does X live?” and “Who lives at Y?”. name VARCHAR (40) address INT(9) Peter Bagnall1 Mickey Mouse2 Goofy2 address VARCHAR (200) id INT(9) Castle Park…1 Disneyland2

dbwebsites 2.7 Schemas The schema of a database is the design of the tables, and the way they join together. Designing the schema for a database is important, since it can be very hard to change it once a website is using it without a lot of downtime or programming effort.

dbwebsites 2.8 Schemas - Simplest Just a single table. Works for simple lists of records. First Name Char(20) Surname Char(20) Human Enum(yes,no) Age Int Phone Char(15) Char(70) PeterBagnallYes But people may have home phone, work phone, and mobile phone. You could add more fields (aka columns) for the extra phone numbers, or…

dbwebsites 2.9 Schemas – One to Many Can deal with a record of one type relating to several records of another type. First Name Char(20) Surname Char(20) Human Enum(yes,no) Age Int(3) ID Int(8) Char(70) Phone Number Char(15) Type Enum(‘home’,’mobile’,’work’,’work fax’) owner Int(8) home mobile work work fax home2

dbwebsites 2.10 Types of Relationships One to One Username Password One to Many Customer -> Orders Many to Many Actors Movies

dbwebsites 2.11 Schemas – Many to Many Actors Name varchar(50) DoB Date ID Int(8) Michael Caine14 March Donald Sutherland17 July Movies Title Varchar(200) ReleaseDate Year(4) ID Int(8) The Italian Job19691 Outbreak19952 Get Carter20003 Get Carter19714 Roles Movie Int(8) Actor Int(8) Played Varchar(200) 11Charlie Croker 22Maj. Gen. Donald McClintock 31Cliff Brumby 41Jack Carter

dbwebsites 2.12 Connect to the DB server You can access the database interactively through the windows command line. mysql -u user -h host –p User is the username on the database. Host is the computer which the database is running on. Once connected you use SQL to give commands to the database.

dbwebsites 2.13 SQL – Structured Query Language SQL is the language used to manipulate databases. mysql> show databases; | Database | | mysql | row in set (0.00 sec)

dbwebsites 2.14 Create a database mysql> create database movies; Query OK, 1 row affected (0.00 sec) Now there is a database you can use

dbwebsites 2.15 Create some tables Next you need to create some tables in the database to hold actual data. First the actors… mysql> create table actors (name varchar(50), dob date, id INT(8) AUTO_INCREMENT primary key); Query OK, 0 rows affected (0.05 sec)

dbwebsites 2.16 Create more tables Next the movies… mysql> create table movies (title varchar(200), releasedate YEAR, id INT(8) AUTO_INCREMENT primary key); Query OK, 0 rows affected (0.03 sec)

dbwebsites 2.17 Create last table Finally the roles, which links the other two tables. mysql> create table roles (movie int(8), actor int(8), played varchar(200)); Query OK, 0 rows affected (0.03 sec)

dbwebsites 2.18 Check the tables You can look at the structure of a table using… mysql> describe actors; | Field | Type | Null | Key | Default | Extra | | name | varchar(50) | YES | | NULL | | | dob | year(4) | YES | | NULL | | | id | int(8) | | PRI | NULL | auto_increment | rows in set (0.05 sec)

dbwebsites 2.19 Insert some data into the database Tell it about some actors… mysql> insert into actors (name, dob) values (“Michael Caine”,” ”); 1 row in set (0.05 sec) Dates are entered (most easily) in Japanese format. The id field is not entered since it is automatically generated by the database.

dbwebsites 2.20 Insert more data into the database Tell it about some movies… mysql> insert into movies (title, releasedate) values (“The Italian Job”,”1969”); 1 row in set (0.05 sec) The id field is not entered since it is automatically generated by the database.

dbwebsites 2.21 Which IDs were used? See what actually went into the database… mysql> select id, name from actors; | id | name | | 1 | Michael Caine | row in set (0.00 sec)3 mysql> select id, title from movies; | id | title | | 1 | The Italian Job | row in set (0.00 sec)

dbwebsites 2.22 Insert more data into the database Now link the actors to the movies… mysql> insert into roles (movie, actor, played) values(1,1,”Charlie Croker”); 1 row in set (0.05 sec) The first 1 entered is the id of the movie. The second 1 is the id of the actor.

dbwebsites 2.23 Answering useful questions Now that we have a database, with data in it we can do useful queries. Say we want to know who played in “The Italian Job”. First find the movie id… mysql> select id from movies where title=“The Italian Job”; | id | | 1 | row in set (0.00 sec)

dbwebsites 2.24 Answering useful questions Next link the find any actor id’s which are listed in the roles as having been in The Italian Job. mysql> select actor from roles where movie=1; | actor | | 1 | row in set (0.00 sec)

dbwebsites 2.25 Answering useful questions Finally find which actor has the appropriate id. mysql> select name from actors where id=1; | name | | Michael Caine | row in set (0.00 sec)

dbwebsites 2.26 All in one query! Or we can combine all those queries into a single query and have the database do all the work for us… mysql> select actors.name from actors, roles, movies where movies.title = "The Italian Job" and movies.id = roles.movie and roles.actor = actors.id; | name | | Michael Caine | row in set (0.00 sec)

dbwebsites 2.27 Questions? Presentation online at… tech/howitworks/dbwebsites/