Class 1Intro to Databases Goals of this class Understand the architecture behind web database...

22
Class 1 Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational databases are and how they work Understand how to interact with a database using PHP Understand how to output to a client Understand how to design & construct a database Understand how to construct a site that uses dynamic content Gain an understanding of the cultural importance of databases in current culture – both professional and artistic

Transcript of Class 1Intro to Databases Goals of this class Understand the architecture behind web database...

Page 1: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to Databases

Goals of this class

Understand the architecture behind web database applications

Gain a basic understanding of what relational databases are and how they work

Understand how to interact with a database using PHP

Understand how to output to a client

Understand how to design & construct a database

Understand how to construct a site that uses dynamic content

Gain an understanding of the cultural importance of databases in current culture – both professional and artistic

Page 2: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to Databases

Understand the architecture behind web database applications

A 3-tier application is an application program that is organized into three major parts, each of which is distributed to a different place or places in a network.

The three parts are: The Client Tier

presentation interfaceHtml or flash

The Middle Tier application logicPHP

The Database Tier database and programmingrelated to managing itMySQL

Page 3: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to Databases

What relational databases are and how they work

A relational database is a collection of data items organized as a set of formally-described tables from which data can be accessed or reassembled in many different ways without having to reorganize the database tables.

In addition to being relatively easy to create and access, a relational database has the important advantage of being easy to extend.

After the original database creation, a new data category can be added without requiring that all existing applications be modified.

The relational database was invented by E. F. Codd at IBM in 1970.

Page 4: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to Databases

What relational databases are and how they work

DatabaseUser Table

User Name Password Country

Fred Apple 1

Mary Orange 2

Sue Kiwi 1

Country Table

ID Country

1 Canada

2 Mexico

3 USA

A database is made up of tables

Each table has defined columns or fieldsrows or records

Page 5: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to Databases

What relational databases are and how they work

The standard user and application program interface to a relational database is the structured query language (SQL). SQL statements are used both for interactive queries for information from a relational database and for gathering data for reports

Page 6: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to Databases

Understand how to interact with a database using PHP

PHP is used to ask questions and retrieve answers from a Database

PHP is designed to work with SQL databases. It can format questions in a way the database can understand

PHP has several specific commands that allow it to talk to MySQL

PHP is used to output HTML to a browser, or pass information to another client-side application like Flash

Page 7: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to Databases

Understand how to output to a client

Data stored in a database is usually free of any presentation markup. This means that when it is retrieved from a database nothing determines what it will look like, or how it will be displayed.

This separation of content and display means that the same content can be retrieved and displayed in several formats or mediums

HTMLFLASHPDACELL PHONEPDFETC

It also means that applications that use databases can be easily updated or redesigned.

Page 8: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to Databases

Understand how to design & construct a database

The design of a database is one of the most important parts of a dynamic website. It determines

What type of data can be storedHow easily information can be accessedHow fast information can be accessedWhat types of relationships can be made between the dataHow easily a database can be extended

Database Architects (DBAs) usually design databases

Page 9: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to Databases

Understand how to construct a site that uses dynamic content

Most site that use dynamic content display their pages in templates

A template is an html page (etc) with “buckets” for content

To design templates you need to understandHow to retrieve data from a databaseHow to format this data for displayThe basics of graphic design & user interface

Page 10: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to Databases

Understand how to construct a site that uses dynamic content

Page 11: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to Databases

Understand how to construct a site that uses dynamic content

Page 12: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to Databases

The cultural importance of databases – both professional and artistic

changes in how weorganizeperceive

separation of content and contextcontent and display

Page 13: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to Databases

PHP Basics

What is PHP?

PHP: Hypertext Preprocessor

PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.

Like any language, PHP is made up ofVariable typesBuilt in functionsIt supports user defined functionsIt is designed to work with SQLIt has it’s own syntax

Page 14: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to Databases

PHP Basics

Variable types The “type” of a variable describes what sort of information a variable can store, as well as how much space that information takes up. (Think Tupperware)

Scalar Types Variables of a scalar type can contain a single value at any given time Boolean $registered=TRUE;integer $age=26;float $weekly_pay=12,444.33;string $name=“Fred”;

Constants define("pi", 3.14159);

Page 15: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to Databases

PHP Basics

Syntax

Starting and Ending a program<?…?> Ending a statementStatements end with a semi-colon, “;”. (Forgetting this is a common mistake)

File ExtensionsIn order for a server to recognize a php file it must end in .php

Comments# this is a comment// this is also a comment

Page 16: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to Databases

PHP Basics

Basic Commands

Declaring a variableassigns a value to a variable$name=“Fred”;

PrintPrint outputs as text. It can be used for plain text files or htmlprint(“Hi”);

Page 17: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to Databases

PHP Basics

Outputting to HTML

HTML<html><body><b>Hi. Our class is called “Intro to Databases”.</b></body></html>

PHP<?print(“<html>”);print(“< body>”);print(“< b>Hi. Our class is called \“Intro to Databases \“.</b>”);print(“< /body>”);print(“< /html>”);?>Note that the quote is escaped.

Page 18: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to Databases

PHP Basics

Outputting to HTML with variables

HTML<html><body><b>Hi. My name is Sharon.</b></body></html>

PHP<?$name=“Sharon”;print(“<html>”);print(“< body>”);print(“< b>Hi. My name is $name .</b>”);print(“< /body>”);print(“< /html>”);?>

Page 19: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to Databases

PHP Basics

Simple User Defined Functions<?$a=12;$b=24;

print(“<html>”);print(“< body>”);print(“$a + $b<br>”);print(“is equal to<br>”);add_two_numbers($a, $b);print(“< /body>”);print(“< /html>”);

function add_two_numbers($a, $b){$c= $a + $b;print(“$c”);

}

?>

Page 20: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to Databases

PHP Basics

Simple User Defined Functions - A Better Way<?$a=12;$b=24;$c=add_two_numbers($a, $b);

print(“<html>”);print(“< body>”);print(“$a + $b is equal to $c”);print(“< /body>”);print(“< /html>”);

function add_two_numbers($a, $b){$c= $a + $b;return $c;

}

?>

Page 21: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to DatabasesPHP Basics

Constructing a simple template<?//declare variables$background=“#ffff00”;$fontcolor=“#000000”;$username=“Fred”;$content=“Hi”.$username;

// start html pageprint(“<html>”);print(“< body bgcolor= \”$background \”>”);print(“<font color=\”$fontcolor \”>”);

// display content hereprint(“$content”);// end display content

// end page print(“</font>”);print(“< /body>”);print(“< /html>”);

?>

Page 22: Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.

Class 1Intro to DatabasesPHP Basics

Common Errors<?//declare variables$background=“#ffff00”;$fontcolor=“#000000”;$username=“Fred”;$content=“Hi”.$username;

// start html pageprint(“<html>”);print(“< body bgcolor= ”$background” >”);print(“<font color=\”$fontcolor \”>”);

// display content hereprint(“$content”);// end display content

// end page print(“</font>”);print(“< /body>”);print(“< /html>”);

?>

Parse error: parse error in /home/denning/www/sp2004/cl_01/examples/template.php on line 8

Here the quotes are not escaped