PHP and active pages Logical models for - - PowerPoint PPT Presentation

php and active pages logical models for db web apps
SMART_READER_LITE
LIVE PREVIEW

PHP and active pages Logical models for - - PowerPoint PPT Presentation

Telecom SudParis Introduction sessions management and transactions PHP and active pages Logical models for DB-web apps. Evolutions Bruno DEFUDE


slide-1
SLIDE 1

Telecom SudParis 1

  • Bruno DEFUDE

Computer Science Dept

  • Introduction

sessions management and transactions PHP and active pages Logical models for DB-web apps. Evolutions

Framework Web services

  • WWW – Web advantages

Universal client Easy to use Open standards Good integration with other Internet services and

protocols

Extensible Low software and network costs Corporate network (Intranet), inter-companies network

(extranet), WAN

  • Web is a kind of DB but

Without schema Without query language Without transactions, recovery, … Without powerfull authorisation mechanism

DBs store huge amount of data which are

interesting to publish on the web

slide-2
SLIDE 2

Telecom SudParis 2

  • Transform DBs into sets of static web pages

Simple Redundency, problem of consistency Disadvantages of web

Need to generate dynamic web pages

constructed with DB content

!"#$

Browser (client) HTTP server DBMS url Html result CGI query string SQL HTML

%

& "'"#$

Simple and portable Lots of code to write (one CGI per query!):

can be improved with generic solutions

Not very efficient

(

) "#$

Client 1 Client 2 Client 3 C G I

Server Process

Process 1 Process 1 Process 1 HTTP Server CGI Scripts

slide-3
SLIDE 3

Telecom SudParis 3

*

) +&$

Client 1 Client 2 Client 3

Server Process

HTTP Server API

Set of functions

Thread 1 Thread 2 Thread 3 CGI scripts are functions of a DLL, Processed As threads within the multi-threaded HTTP server

,

2nd solution : dedicated gateways (ex. IDC)

BD

W3 client IIS IDC driver SQL Server ODBC SQL Server HTTP ISAPI .idc .htx SQL (via API ODBC) SQL

(via API SQL Server)

  • ! - .

Strong coupling of a PL and web (direct calls

from a web page, direct support by a HTTP server)

The language run-time supports sessions PHP, servlet – JSP (Java), ASP (Microsoft)

  • " '

no standard spaghetti style programs efficient

  • Var. sessions

A real PL Server-side Scripts Limited functionalities Little programming Dedicated gateways inefficient Difficult to program web Standard CGI Scripts Cons Pros Solution

slide-4
SLIDE 4

Telecom SudParis 4

  • WWW – Web limitations

performances

Internet network => increase bandwith CGI scripts => FastCGI, server-side scripts

security

HTTP => S-HTTP secure TCP/IP level => SSL protocol

  • WWW – Web Limitations (2)

Transaction management

not possible with HTTP 1.0

  • no session mode
  • One can use "cookies"

Possible with HTTP 1.1

  • Allows persistent connexion (TCP level)

User interface

HTML is not very powerfull to construct sophisticated UI Java or Flash is more powerfull

  • Introduction

sessions management and transactions PHP and active pages Logical models for DB-web apps. Evolutions

Framework Web services

/

  • Need to share information betaween different

pages/scripts

Authentification: only one authentification for

n actions

History of actions Incremental state construction DB Transactions

slide-5
SLIDE 5

Telecom SudParis 5

transaction = DB program (read and write

sequence)

ACID properties

A : Atomicity C : Consistency I : Isolation D : Durability

12 ' -

  • n-line ordering (music, books, planes, …)

bank insurance e-business!!!!

Transaction = sequence of URL invocations

(management context by the web?)

Transaction = ACID properties (ensured by the

DBMS)

HTTP = no session support

  • Client-side management context (cookies)
  • Simulation of HTTP sessions (transactional web)
  • Use server-side scripting languages (PHP, ASP, JSP, ...)

0 3

Browser (client) http server cgi DBMS

1 1 1’ c1 1’ c1 2 c1 2 c1 2’ c1, c2 2’ c1, c2 3 fin c1, c2 3 fin c1, c2 4 sql(c1, c2) 5’ del(c1, c2) 5’ del(c1, c2) 4’ ok

1 : first access 1’ : c1 cookie is generated 2 : other access with c1 cookie transport 2’ : c1, c2 cookies are generated 3 : end of transaction with c1, c2 transport 4 : transaction is constructed and processed on the DBMS 5’ : cookies deletion

slide-6
SLIDE 6

Telecom SudParis 6

0 345

Context is managed on client-side (cookies) advantages:

Easy to code DB access is done one time at the end of the session

(DB resources are not blocked)

If no explicit user termination, nothing to do (at DB level)

0 345

Cons

Not really transactional Limited functionality Lots of cgi scripts to code

Cookies problems

global to a user (no distinction between two windows) global to a url (does not allow two different

transactions on the same site at the same site)

browser (Client) http Server cgi daemon gateway DBMS

Context is managed by a daemon on server-

side

Need of a transaction id stored on client-side

(cookie or rewritten URL) and on server-side (in an array of the daemon)

A gateway does not process a single query

but a complete transaction (a sequence of queries)

slide-7
SLIDE 7

Telecom SudParis 7

45

1 : transaction beginning request (implicite or

explicite)

An id is allocated by the daemon, transactions array is

updated, a gateway is launched, an id is send back to the client (cookie or rewritten URL)

2 : DB operation request

The request is routed by the daemon on the right

gateway using the transaction id and the transactions array

45

3 : transaction ending request

implicit : error, timeout explicit : idem 2 + update of transactions array, id is

deleted on client-side and the gateway is stopped

6

Pros

really transactional generic solution

Cons

complex architecture DB resources are blocked until the end of the

transaction

Need to detect a user « abort » (timeout)

(

  • URL rewriting: variables passing using GET

mode of forms

sessions variables: server-side scripts Cookies: client-side storage of variables DB storage: context is stored in a DB

identified by a session identifier

slide-8
SLIDE 8

Telecom SudParis 8

*

" '

  • Large volume

More complex to program DB storage values + references limited volume session Variables simple Restriceted to values Global to a browser Cookies simple No protection Intrusive Restricted to values URL rewriting

Pros Cons Mode

,

  • Introduction

sessions management and transactions PHP and active pages Logical models for DB-web apps. Evolutions

Framework Web services

  • 4 - .5

Offer a programming language integrated to the web

(ability to have calls from a web page, associated to a HTTP server)

run-time of the language offers session support (and

consequently of transactions)

PHP, servlet - JSP, ASP, XSP (Cocoon) see Java and PHP for more details

&7&- '

  • pensource solution for active server pages

An active page is a server-side script

(generalises CGI and ISAPI)

Supported by an interpretor linked to the

HTTP server

DB interface using a specific API or an

abstract layer

slide-9
SLIDE 9

Telecom SudParis 9

& '- -

Client Server Browser HTTP Decoding Page query Active page PHP PHP Interpretor DB dynamic Page Add HTTP envelop HTTP Encoding

# +

Internet HTTP Server PHP Interpreter DBMS API DBMS actives Pages (PHP files) SSinclude

'-

<HTML> <HEAD> … </HEAD> <BODY> <?php …………….. ?> <SCRIPT LANGUAGE=Javascript> … </SCRIPT> <!--#Include … --> <TABLE> … </TABLE> </BODY> </HTML>

Simple HTML Sections Server-side Script Client-side Script SSI (script or HTML in external file) Simple HTML Client Server

variables Cookies $_COOKIES Forms $_GET, $_POST Environment $_ENV ServerVariables $_SERVER ClientCertificate variables Cookies variables SESSION

slide-10
SLIDE 10

Telecom SudParis 10

%

12 ''

<?php echo "<h1 align=center>My first PHP program to process forms </h1>"; echo "<br><br><ul>"; echo "<li>Name = ".$_POST["Name"]; echo "<li>First name = ".$_POST["FName"]; echo "<li>City = ".$_POST["City"]; echo "<li>Country = ".$_POST["Countryepartement"]; echo "</ul>"; ?> <br><br>see <a href="display.txt">source</a>

(

12 '

<?php include('init-ado.php'); $connection = &ADONewConnection('mysql'); $connection->Connect (dbnode, dbuser, dbpasswd, dbinstance); $reqsql=$_GET[‘reqsql’]; $rs=$connection->Execute($reqsql); if ($rs == false) die("failed"); print '<p>Number of tuples = '.$rs->RecordCount(); print '<p><table border=1><tr>'; for ($i=0; $i<$rs->FieldCount(); $i++) { $ff = $rs->FetchField($i); print '<td>'.$ff->name. '</td>'; } print '</tr>'; while ($arr = $rs->FetchRow()) { print '<tr>'; for ($i=0; $i<$rs->FieldCount(); $i++) { print '<td>'.$arr[$i].'</td>'; } print '</tr>'; } print '</table>'; ?>

*

  • Introduction

sessions management and transactions PHP and active pages Logical models for DB-web apps. Evolutions

Framework Web services

,

8 ' .

Need to model

Navigation (chaining between pages/scripts) Information sharing between pages/scripts Session (start, end, adding informations) DB Access (tables and interactions)

Is not a precise desciption of the UI (grouping

pages is possible, use of frames, …)

slide-11
SLIDE 11

Telecom SudParis 11

  • 6. 2

Navigating in the publications of a conference

set (journées Bases de Données Avancées)

Different ways to navigate: using years,

authors, titles, …

No updates (external to the application)

  • 8

static Form author title

Main Menu give Author, title List author List publis

dynamic Form

List conferences Stats List publis author Author (select) Publication, publish (select) Conferences (select) Conferences, Publication, Publish, Author (select) Publication, publish (select)

author auteur author

conference conference

  • + 2

E-commerce Authentification is needed administrator Session: add products,

categories…

User Session: navigate and buy

  • 8

Main page login give user Affiche catalogue List articles display category logout Buy article add user add product display caddie add category

Session admin + idfuser Session client + idfuser, fname, lname Login passwd user Infos User (insert) Order (select) Commande (insert) Article (select) Categorie (select) nocategory noarticle End current session Nocategory father nocategory Product (insert) ProdCat (insert) Categorie (insert)

dynamic Form static Form

slide-12
SLIDE 12

Telecom SudParis 12

  • Introduction

sessions management and transactions PHP and active pages Logical models for DB-web apps. Evolutions

Framework Web services

/

3

In computer programming, a software

framework is an abstraction in which software providing generic functionality can be selectively changed by user code, thus providing application specific

  • software. It is a collection of software

libraries providing a defined application programming interface (API). (Wikipedia)

%

9 3' &7&

  • pen-source library for PHP5

implements

Data abstraction MVC model (Model – View – Controler) Forms Abstraction authentification

Interface to

Web services Ajax (JSON)

http://framework.zend.com

(

& :;"

Apache Struts for Java Zend Framework for

php

Spring.NET CairnGorm for Flex …

  • UI layer

Data layer Business layer

slide-13
SLIDE 13

Telecom SudParis 13

*

the Web today

Design for client-application interactions Implemented around 2 standards http and html Allow to support e-commerce apps

The future Web ?

the Web is everywhere. What can we do with it ? E-marketplaces Business process integration sharing resources Existing solutions are ad hoc e.g. application-application interactions with html forms goal: allowing application-application interactions ,

'

First Genération

Static Web Pages (HTML)

2nd Genération

Real applications

(Dynamic Web Pages, ASP, JSP, PHP, ...)

3rd Generation

Web services (based on XML)

  • <:8

Extensible Markup Language a syntaxe for documents a meta markup language A way to represent informations Is not reserved for Web pages

  • <:812

<?xml version="1.0" encoding="ISO-8859-1"?> <BIBLIO> <BOOK ISBN="9782212090819" LANG="fr" SUBJECT="applications"> <AUTHOR> <FIRSTNAME>Jean-Christophe</FIRSTNAME><LASTNAME>Bernadac</LASTNAME> </AUTHOR> <AUTHOR> <FIRSTNAME>François</FIRSTNAME><LASTNAME>Knab</LASTNAME> </AUTHOR> <TITLE>Construire une application XML</TITLE> <PUBLISHER> <NAME>Eyrolles</NAME> <PLACE>Paris</PLACE> </PUBLISHER> <DATEPUB>1999</DATEPUB> </BOOK> <BOOK ISBN="9782212090529" LANG="fr" SUBJECT="général"> <AUTHOR> <FIRSTNAME>Alain</FIRSTNAME><LASTNAME>Michard</LASTNAME> </AUTHOR> <TITLE>XML, Langage et Applications</TITLE> <PUBLISHER> <NAME>Eyrolles</NAME> <PLACE>Paris</PLACE> </PUBLISHER> <DATEPUB>1998</DATEPUB> </BOOK> </BIBLIO>

slide-14
SLIDE 14

Telecom SudParis 14

  • 0<:8

XML Document

Controling, typing

DTD, XML schema

programing

SAX, DOM

exchanging

SOAP

presenting

CSS XSLT XSLFO SMIL

transforming

XSLT

querying

Xpath, XQuery

linking

Xlink, XPointer

describing RDF

  • !'

A Web service is a software application identified by a URI, whose interfaces and binding(1) are capable of being defined, described and discovered by XML artefacts and supports direct interactions with other software applications using XML based messages via Internet-based protocols. (W3C definition)

(1) An association between an Interface, a concrete protocol and a data format

  • !'

characteristics:

Web services are reusable Independent of:

OS (UNIX, Windows,…) their implementation (Java, C++, Visual Basic,…) underlying architecture (.NET, J2EE,…)

/

  • +
slide-15
SLIDE 15

Telecom SudParis 15

%

Conclusion

Web can be used as a global entreprise

infrastructure

Lack of sessions support is problematic Active server pages technologies simplify

software development:

Take care to spaghetti style programs (use web

framework and logical models)

Web services allow to easily apply weak coupling of

inter or intra entreprise applications