introductory online database concepts manzur ashraf

67
Introductory Online Database Concepts Manzur Ashraf

Upload: lauren-rice

Post on 26-Dec-2015

227 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Introductory Online Database Concepts Manzur Ashraf

Introductory Online Database Concepts

Manzur Ashraf

Page 2: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 2

Syllabus of Short Course

Beginning: (3 classes) Web architecture & preliminaries of

PHP & MySQLPHP issuesPHP & MySQL connectivity

Advanced: (3 classes)Review & efficient PHP issuesPHP ‘string’ & ‘array’ in depth Dynamic Image creation using PHP

Page 3: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 3

Client Server Architecture

Page 4: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 4

Thick client architecture

Page 5: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 5

Thin client architecture

Page 6: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 6

Thick versus thin client

Bandwidth Theoretical maximum file size that can be downloaded in 20 sec

28.8 kbps (Slow Modem)

70.3 KB

56.6 kbps (Fast Modem)

138.1 KB

2Mbps (ADSL) 4882.8 KB

10Mbps (Cable Modem)

24414.1 KB

Page 7: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 7

Application server architecture

Page 8: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 8

Transactional application server architecture

Page 9: Introductory Online Database Concepts Manzur Ashraf

Internet and WWW

Page 10: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 10

The InternetA worldwide network connecting millions

of hosts Interconnecting many Local Area

Networks (LANs) (inter-network or just Internet)

The LANs connected to the Internet can be of various types

A host is a computer that is connected to the Internet

Page 11: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 11

History of the Internet It started as a United States government

project, sponsored by the Advanced Research Projects Agency (ARPA), and was originally called the ARPANET

The Internet grew quickly throughout the 1980s and 90s

Less than 600 computers were connected to the Internet in 1983; now there are over 10 million

Page 12: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 12

Internet ApplicationsEmail World-Wide Web FTP Telnet Newsgroups Chat...

Page 13: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 13

Web ServersThese pieces of information

are stored as files on particular hosts of the Internet

These hosts are called Web servers

Page 14: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 14

Information Types on the Web

The information pieces of the Web can be of textual nature, images, video, audio, programs or any other type of information

Every type of information can have different formats for storing it as a file

For example, some formats for storing images are jpeg, bmp, gif, ps, pdf

Page 15: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 15

HTMLMuch of the information that is found on

the Web is stored as HTML files HTML is a markup language for formatting

text. In addition, HTML facilitates inclusion of other types of information (such as images) in our text documents

Here is an example of an HTML documentThis is how it looks like when displayed

inside a browser

Page 16: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 16

Browsers

We use a browser to display HTML documents

The browser is responsible for fetching the documents and displaying their contents according to the HTML rules

Page 17: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 17

URLsEach information piece on the Web has

a unique identifying address which is called a URL (Uniform Resource Locator)

A URL takes the following form: http://www.huji.ac.il/index.html

It has 3 parts: a protocol field, a hostname field and a file field

protocol filehostname

Page 18: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 18

URL Fields

The protocol field (“http” in the previous example) specifies the way in which the information should be accessed

The host field specifies the host on which the information is found

The file field specifies the particular location in the host's file system where the file is found

There could be more complex forms of URLs, but we do not discuss them

Page 19: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 19

Search Engines

What are search engines? How do they work? Shortcomings of search

engines Some popular search engines:

Infoseek, HotBot, Altavista, Excite, Lycos, Yahoo!, Jeeves,...

Page 20: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 20

IP (Internet-Protocol) Addresses

Hostnames are used by people. The network mechanism uses IP-addresses instead

Every host connected to the Internet has a unique IP address that identifies it

IP addresses are 32-bit numbers that are usually written as four decimal numbers separated by dots, e.g. 135.17.98.240, where the numbers refer to the four bytes composing this address

Page 21: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 21

IP Packets

Information that is sent over a network is often broken down in parts, called packets, which are sent to the receiving machine and then reassembled

In the Internet, data is transferred from one host to another is divided into IP-packets

Page 22: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 22

Routing IP PacketsThe essential role of the Internet is to enable

every host to send IP-packets to any other host Each IP-packet contains source and target IP-

addressesThere is a routing protocol that handles the

transfer of packets to their target hosts, according to the target IP addresses

The sending host only needs to know the IP address of the target host it wishes to communicate with

Page 23: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 23

Using IP Addresses

How does the browser know the IP address of the Web server?

One possibility is that the user explicitly specifies the IP address of the server in the host field of the URL, for example:

http://135.17.98.240/index.html However, it is inconvenient for people to

remember such addresses

Page 24: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 24

Generic Domains There are 7 special domains that are called generic

domains com - commercial organizations

(www.cocacola.com) edu - educational institutions (www.berkeley.com) gov - U.S. governmental organizations

(www.cia.gov) int - international organizations mil - U.S. military net - networks (InterNIC) org - other organizations (www.w3.org)

Page 25: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 25

Country Domains

Generic domains usually refer to hosts inside the U.S. Other countries use two-letter country domains: il - Israel uk - United Kingdom jp - Japan se - Sweden

These domains usually have sub-domains that correspond to the generic domains. For example, co.il is the domain of all the commercial organizations in Israel, and ac.il is the domain of all the academic institutions inside Israel

Page 26: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 26

Back to the BrowserWhen we address a host in the Internet,

we usually use its hostname (e.g., using a hostname in a URL)

The browser needs to map this hostname into the corresponding IP address of the given host

There is no one-to-one correspondence between the sections of an IP address and the sections of a hostname

Page 27: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 27

Translating IP Addresses to HostnamesThe translation of IP addresses to

hostnames requires a lookup tableSince there are millions of hosts on the

Internet, it is not feasible for the browser to hold a table which maps all hostnames to their IP-addresses

Moreover, new hosts are added to the Internet every day and hosts change their names

Page 28: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 28

DNS

The browser (and other Internet applications) use a DNS-Server to map hostnames to IP addresses

DNS (Domain Name System) is an hierarchical scheme for naming hosts

Page 29: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 29

Proxy Servers

A proxy server acts as a delegate of browsers for accessing the Web

The browser transfers the requests for a document to the Proxy

The Proxy contacts the suitable Web-server and fetches the document on behalf of the browser

Page 30: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 30

FirewallsA firewall poses restrictions on

the traffic in or out of a local-area network

Examples: Hides sensitive data from the

outside world Prevents access of local users to

specific sites outside the local-area network

Page 31: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 31

How a Firewall WorksAll the traffic (of IP-packets) in

or out of the local-area network is forced to go through a single host

A firewall application is installed on this host

The firewall examines all the in and out traffic of IP-packets and discards illegal packets

Page 32: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 32

Dynamically Generated Documents

host www.excite.com

HTTPD

applicationBrowser

user requests

http://www.excite.com/search?what=something

GET /search?what=something

sends the

contents of

index.html

execution of

search program

Page 33: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 33

IP Addresses

Class

A

B

C

D

E

From

0.0.0.0

128.0.0.0

192.0.0.0

224.0.0.0

240.0.0.0

Till

127.255.255.255

191.255.255.255

233.255.255.255

239.255.255.255

247.255.255.255

Net ID

7 bit

14 bit

21 bit

28 bit

27 bit

Host ID

24 bit

16 bit

8 bit

-

-

Class Network ID Host ID

32 bit

InterNIC

Page 34: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 34

Routing

Page 35: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 35

Transport LayerTCP

Connection oriented Reliable, keeps order

UDP Connectionless Unreliable Fast

Page 36: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 36

Client-Server Model

Server application Client applicationPort 5746

Server machine

144.12.34.99

Client machine

190.30.42.155

Page 37: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 37

Well-Known PortsFTP 21Telnet 23HTTPD 80...

Page 38: Introductory Online Database Concepts Manzur Ashraf

HTTP Basics

Page 39: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 39

Previous HTTP VersionsHTTP/0.9 used by WWW since 1990HTTP/1.0 [RFC 1945] Supports MIME (Multipurpose Internet Mail

Extension) messages [RFC 1341] MIME transmits non-textual files by encoding

them Content negotiation

HTTP/1.1 [RFC 2068] Persistent connections Caching

Page 40: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 40

General FeaturesLightness and speed(response time of 100 ms in a hypertext jump)

Client-Server protocolStateless object-oriented protocolOpen-ended set of methods and headersTyping and negotiation of data representation

Page 41: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 41

TerminologyUser agent: client which initiates a request (browser, editor, web robot, …)Origin server: the server on which a given resource residesProxy: acts as both a server and a clientGateway: server which acts as intermediary for other serversTunnel: acts as a blind relay between two connections

Page 42: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 42

Client-Server ProtocolThe browser is the clientThe client sends requests to an HTTP Server

Page 43: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 43

Client-Server Sessions

The HTTP protocol supports a short conversation between browser and serverThe entire conversation is conducted using ASCII characters (8-bit)The standard (and default) port for HTTP servers to listen on is 80, though they can use any port

Page 44: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 44

HTTP Session

A basic HTTP session has four phases: Client opens the connection (a TCP

connection) Client makes the request Server sends a response Server closes the connection

Page 45: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 45

Nested Objects

Suppose a client accesses a page containing 10 inline images; to display the page completely would require 11 HTTP sessionsSome browsers/servers support a feature called keep-alive which can keep the connection open until it is explicitly closed

Page 46: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 46

Stateless Protocol

HTTP is a stateless protocol, which means that once a server has delivered the requested data to a client, the connection is broken, and the server retains no memory of what has just taken place

Page 47: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 47

URL

Universal Resource Identifiers [RFC 2396] are used to specify the object of a method as an address (URL) as a name (URN)

URL = “http://” host [“:” port] [path]

IP addresses in URLs should be avoided [RFC 1900]

Page 48: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 48

Format of Request and Response

An initial line Zero or more header lines A blank line (i.e., a CRLF by itself), and An optional message body (e.g., a file, query data, or query output)

Note: CRLF = “\r\n” (usually ASCII 13 followed by ASCII 10)

Page 49: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 49

Request

A request consists of: Initial line Headers Blank line Message body

Page 50: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 50

Request Example

GET /courses/dbi/index.html HTTP/1.0

From: [email protected] User-Agent: HTTPTool/1.0 [blank line here] Method Path Version Headers

Initial line

Page 51: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 51

Request MethodsGET returns the contents of the indicated document The most frequently used command

HEAD returns the header information for the indicated document Useful for finding out info about a

resource without retrieving it

POST treats the document as a script and sends some data to it

Page 52: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 52

More MethodsPUT replaces the contents of the document with some dataDELETE deletes the indicated documentTRACE invokes a remote loop-back of the request. The final recipient SHOULD reflect the message back to the client

Usually these methods are not allowed

Page 53: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 53

GET Method

GET is the most common HTTP method It says “give me this resource”

Page 54: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 54

HEAD Request

A HEAD request asks the server to return the response headers only, and not the actual resource (i.e., no message body)Same as GET but without the message bodyThis is useful for checking characteristics of a resource without actually downloading it, thus saving bandwidthUsed for testing hypertext links for validity, accessibility and recent modification

Page 55: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 55

Post (cont.)There is a block of data sent with the request, in the message body There are usually extra headers to describe this message body, like Content-Type: and Content-Length:The request URI is a program to handle the sent data, not a resource to retrieveThe HTTP response is normally the output of a program, not a static file

Page 56: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 56

Headers

HTTP 1.0 defines 16 headers none are required

HTTP 1.1 defines 46 headers one header (Host:) is required in

requests

Page 57: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 57

HTTP/1.0 200 OK Date: Fri, 31 Dec 1999 23:59:59 GMT Content-Type: text/html Content-Length: 1354

<html> <body> <h1>Hello World</h1> (more file contents) . . . </body> </html>

Headers

Response ExampleInitial line

Version

Status code

Reason phrase

Message body

Page 58: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 58

Status CodeThe status code is a three-digit integer, and the first digit identifies the general category of response: 1xx indicates an informational message only 2xx indicates success of some kind 3xx redirects the client to another URL 4xx indicates an error on the client's part

Yes, the system blames it on the client if a resource is not found (i.e., 404)

5xx indicates an error on the server's part

Page 59: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 59

Status Code 1xxThe 100 (Continue) Status Allows a client to determine if the

Server is willing to accept the request (based on the request headers) before the client sends the request body

The client’s request must have the header

Expect: 100 (Continue)

101 Status -- Switching Protocols

Page 60: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 60

Status Code 2xxStatus codes 2xx -- Success

The action was successfully received, understood, and accepted 200 OK 201 POST command successful 202 Request accepted 203 GET or HEAD request fulfilled 204 No content

Page 61: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 61

Status Code 3xxStatus codes 3xx -- Redirection

Further action must be taken in order to complete the request 300 Resource found at multiple locations 301 Resource moved permanently 302 Resource moved temporarily 304 Resource has not modified (since

date)

Page 62: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 62

Status Code 4xxStatus codes 4xx -- Client error

The request contains bad syntax or cannot be fulfilled 400 Bad request from client 401 Unauthorized request 402 Payment required for request 403 Resource access forbidden 404 Resource not found 405 Method not allowed for resource 406 Resource type not acceptable

Page 63: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 63

Response InformationDescription of information Server Type of server Date Date and time Content-Length Number of bytes Content-Type Mime type Content-Language English, for example Content-Encoding Data compression Last-Modified Date when last modified Expires Date when file becomes

invalid

Page 64: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 64

Manually Experimenting with HTTP

>host wwwwww.cs.huji.ac.il is a nickname for vafla.cs.huji.ac.ilvafla.cs.huji.ac.il has address 132.65.80.39vafla.cs.huji.as.il mail is handled (pri=10) by

cs.huji.ac.il

>telnet www.cs.huji.ac.il 80Trying 132.65.80.39…Connected to vafla.cs.huji.ac.il.Escape character is ‘^]’.

Page 65: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 65

Sending a Request

>GET /~dbi/index.html HTTP/1.0[blank line]

Page 66: Introductory Online Database Concepts Manzur Ashraf

(c) Manzur Ashraf, KFUPM 2004 66

The Response

HTTP/1.1 200 OKDate: Sun, 11 Mar 2001 21:42:15 GMTServer: Apache/1.3.9 (Unix)Last-Modified: Sun, 25 Feb 2001 21:42:15 GMTContent-Length: 479Content-Type: text/html

<html> (html code …)</html>

Page 67: Introductory Online Database Concepts Manzur Ashraf

End