MS3304: Week 7 Talking to Databases: SQL Basics. Overview Connecting to a database Querying a database Basic SQL syntax for mySQL Writing simple and complex.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

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.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Session 6 Server-side programming - ASP. An ASP page is an HTML page interspersed with server-side code. The.ASP extension instead of.HTM denotes server-side.
Multiple Tiers in Action
1 Creating a Non-Conditional List A- What are you going to do? You will “list” “all of the records” in a database. (it means you will not use any condition!)
Structured Query Language Part I Chapter Three CIS 218.
CORE 2: Information systems and Databases STORAGE & RETRIEVAL 2 : SEARCHING, SELECTING & SORTING.
Resources – MS Access Free Online Training Resources  Using an Access database to store and information (2 min)
DAY 16: ACCESS CHAPTER 2 Tazin Afrin October 10,
WEEK 11 Database Design. Agenda Hybrid Review Create Tables Add, Edit Data Create Relationships in MS Access 2010 Queries.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
Server-side Scripting Powering the webs favourite services.
4-1 INTERNET DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
Chapter 10 Queries and Updating Part C. SQL Copyright 2005 Radian Publishing Co.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
2440: 141 Web Site Administration Database Management Using SQL Professor: Enoch E. Damson.
M1G Introduction to Database Development 6. Building Applications.
Web Services Week 8 Aims: –Using web services as front ends to databases Objectives: –Review of relational databases –Connecting to and querying databases.
1 Accelerated Web Development Course JavaScript and Client side programming Day 2 Rich Roth On The Net
Web Design: Basic to Advanced Techniques Fall 2010 Mondays 7-9pm 200 Sutardja-Dai Hall Databases & SQL Lecture Code:
Microsoft Access 2010 Building and Using Queries.
Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
SQL: Data Manipulation Presented by Mary Choi For CS157B Dr. Sin Min Lee.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Selecting Data.
MS3304: Week 8 Creating a dynamic SQL query from form input.
Concepts of Database Management Seventh Edition
© Anselm Spoerri Web Design Information Visualization Course Prof. Anselm Spoerri
MS3304: Week 6 Conditional statements. Overview The flow of control through a script Boolean Logic Conditional & logical operators Basic decision making.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
Intro to SQL Management Studio. Please Be Sure!! Make sure that your access is read only. If it isn’t, you have the potential to change data within your.
DT228/3 Web Development Databases. Querying a database: Partial info Search engines, on-line catalogues often need to allow user to search a database.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
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.
WEB SECURITY WEEK 2 Computer Security Group University of Texas at Dallas.
IT ELECTIVE 2.  Web server Can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that.
Central Arizona Phoenix LTER Center for Environmental Studies Arizona State University Data Query Peter McCartney RDIFS Training Workshop Sevilleta LTER.
Creating Databases for Web applications Server side vs client side PHP basics Homework: Get your own versions of sending working: both html and Flash!
IS6146 Databases for Management Information Systems Lecture 1: Introduction to IS6146 Rob Gleasure robgleasure.com.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
# 1# 1 QueriesQueries How do we ask questions of the data? What is SELECT? What is FROM? What is WHERE? What is a calculated field? Spring 2010 CS105.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
+ Structured Query Language Part 2 KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall.
Fall Lab 131 CS105 Lab 13 – Logical Operator Precedence and Joining Tables Announcements: MP 3 released Friday, 11/20 Honors project due: Tuesday,
ADVANCED SQL.  The SQL ORDER BY Keyword  The ORDER BY keyword is used to sort the result-set by one or more columns.  The ORDER BY keyword sorts the.
Programming for the Web MySQL Command Line Using PHP with MySQL Dónal Mulligan BSc MA
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
Web Database Programming Using PHP
PDO Database Connections
Web Systems & Technologies
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Chapter 5 Introduction to SQL.
Web Database Programming Using PHP
PDO Database Connections
PHP / MySQL Introduction
Building and Using Queries
SQL.
Web Browser server client 3-Tier Architecture Apache web server PHP
Web DB Programming: PHP
IntroductionToPHP Static vs. Dynamic websites
Tutorial 6 PHP & MySQL Li Xu
PHP Forms and Databases.
Database Connections.
Presentation transcript:

MS3304: Week 7 Talking to Databases: SQL Basics

Overview Connecting to a database Querying a database Basic SQL syntax for mySQL Writing simple and complex SQL statements for mySQL Advanced topic: preview of advanced SQL commands

Review of dynamic web pages URL Request - Sometimes including variables Database Server finds script/HTML template Associated with URL Script/HTML template is passed to interpreter that executes the script instructions This HTML page is returned to the client via the web server Language Interpreter Client Machine   Template/Scripts Web Server  Interpreter plugs data into the HTML template according to script instructions to create an HTML page on the fly Script requests data from the database which is returned to the interpreter

PHP to MySQL communication Client Machine  Database  Template/Scripts Language Interpreter Web Server  Make the connection to the database Compose SQL query Send SQL query

Composing queries: Sample database of MS3304 students What kinds of information would be useful? What data would need to be in the database? How would we ask for this information?

Sample database of MS3304 students: Useful information 1.All info about all students 2.All info for a specific student 3.Attendance sheet for the lecture 4.Attendance sheet for workshops 5.Marks sheet for a group project 6.Marks report sheet for the office 7.List students resitting 8.All student numbers and marks for IT students in

Sample database of MS3304 students: field names and data types firstNamevarchar surnamevarchar studentNumbervarchar groupint cw1int cw2int averageint IT_progtinyint MM_progtinyint teamvarchar

Query information needed Name(s) of field(s) that we want information returned from Criteria for the search Order to sort results in

Query information: your turn Queries 1.All info about all students 2.All info for a specific student 3.Lecture attendance sheet 4.Workshop attendance sheet 5.Team marks sheet 6.Final marks for office 7.List students resitting Database fields firstName surname studentNumber group cw1 cw2 average team IT_prog MM_prog State the fields returned, the fields used for searching criteria, sort order, and criteria statement for each of the above.

What is SQL? SQL (often pronounced “sequel”) stands for Structured Query Language A set of special reserved words organised in a specific order used exclusively for communicating with a database All major databases use SQL although there can be slight differences in the syntax

Writing an query string: basic SQL syntax SELECT which columns FROM which table WHERE conditions ORDER BY fields to sort by

My SQL operators Comparison and Logical Operators =equals !=not equal to <less than >greater than <=less than or equal to >=greater than or equal to ORwhere at least one of the conditions is true ANDwhere all conditions are true NOTwhere the condition is not true

LIKE and wildcards for comparing strings LIKE is used mainly to compare strings –Used in conjunction with two wildcard characters: Percentage sign (%) matches zero or more characters Underscore (_) matches a single character –LIKE and is case insensitive The star character (*) is used as a wildcard to denote all

SQL example statements It is possible to write queries with set values SELECT * FROM students WHERE firstName = 'Bob' SELECT * FROM students WHERE average > 70 ORDER BY studentNumber It is possible to use PHP variables in SQL queries SELECT * FROM students WHERE surname = '$surname' AND firstName = '$firstName'

SQL expression strings: your turn SQL operators/wildcards =equals !=not equal to <less than >greater than <=less than or equal to >=greater than or equal to ORlogical OR ANDlogical AND NOTlogical NOT LIKEstring comparison *Wildcard for all SQL Statement Syntax SELECT which columns FROM which table WHERE conditions ORDER BY fields to sort by Write the SQL query string for the seven queries previously given. The name of the table: students

Advanced Topic: Other SQL terms IS NULLhas a value IS NOT NULLhas no value BETWEENwithin a range NOT BETWEENnot within a range

Advanced Topic: Other uses of SQL Add a new record to a database Update an existing record in a database Carry out complex multi-table queries (called joins)

Overview PHP passes information to the database in order to make a connection Once a connection exists SQL statements are sent from PHP to allow interaction with the database SQL has a specific syntax that may vary slightly depending on the DB