Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 4: Introduction to PHP 3 PHP & MySQL

Similar presentations


Presentation on theme: "Lecture 4: Introduction to PHP 3 PHP & MySQL"— Presentation transcript:

1 Lecture 4: Introduction to PHP 3 PHP & MySQL

2 Web based 3-tier architecture

3 3-tier architecture (application view)

4 Advantages of the 3-tier architecture approach
the ability to separate logical components of an application ensures that applications are easy to manage and understand. i.e experts can be employed that specialise in one of the layers e.g. user interface design because communication can be controlled between each logical tier of an application, changes in one tier, for example, the database access tier, do not have to affect the client component e.g. a change from one DBMS to another would only require a change to the component in the data access layer with little or no effect on the business/logic (middle) or UI layer. specific tools and technologies suited to each layer can be deployed (and may evolve at a different pace) .

5 Web based 3-tier architecture: tools & technologies
Presentation tier – Browser / custom client, Client Side Scripting (JavaScript, ActionScript, VBScript etc.), Applets. Logical Tier – Web Server (Apache, IIS, Websphere etc.); Scripting Languages (PHP, Perl etc.), Programming Languages (Java, C, C# etc), Application Frameworks (Ruby on Rails etc.) Data Tier – Database Management System (DBMS) (Oracle, MySQL, SQL Server, DB2 etc.), XMLDB

6 Using MySQL in the persistence tier:
MySQL Strengths High performance benchmarks very well against commercial dbs Low-cost no cost under open source licence Easy to configure and learn easy to set up, SQL compliant Portable Linux, Unix and Windows versions Open Source source code available for modification

7 Tools to create a simple web-editable database
QSEE MySQL client (or PHPMyAdmin) PHP Script

8 Define ER model in QSEE Generate SQL Create Database MySQL Write Script to process DB

9 QSEE Multi-case diagramming tool Entity-Relationship Diagrams
All UML diagrams ++ Entity-Relationship Diagrams Generates SQL for various targets (including MySQL 4.0) Implements relationships automatically 1- many : adds primary key on 1-side as columns in the many side to make foreign keys Many-many : adds an new link table with the primary keys from both sides as foreign keys (and a joint primary key) Dependent (weak) entities : foreign key becomes part of the primary key Sets up the appropriate integrity constraints Action on delete and update for foreign keys

10 GUI interface to MySQL server (shares)
PHPMyAdmin GUI interface to MySQL server (shares) GUI runs on stocks (the PHP server) Full access to a database for Creating tables Added data Browsing the data Import and Export of tables… Execute SQL queries (DML) or definitions (DML) But ..

11 PHPMyAdmin Interface

12 Command line MySQL Generated SQL comments are rejected by PHPMyAdmin login to shares directly using putty change directory to your project directory Enter: mysql –p use database source proj.sql

13 Command line MySQL

14 PHP/MySQL a simple example (1):
DB Library - Table Book id title author 1 MySQL in Nutshell Dyer 2 PHP and MySQL Ullman 3 Javascript Smith

15 PHP/MySQL a simple example (2):
// set up server, username, password & database $host="localhost"; // would be "shares" in cems $un="root"; // would be unix user in cems $pw=""; // would be original cems passsword $db="Library"; // would be unix user name // connect to the mysql server mysql_connect($host,$un,$pw); // select the database @mysql_select_db($db) or die( "Unable to select database");

16 PHP/MySQL a simple example (3):
// build the query $query="SELECT * FROM book"; // run the query $result=mysql_query($query); // count the rows returned $num=mysql_numrows($result); // close the connection mysql_close();

17 PHP/MySQL a simple example (4):
// run a loop outputting one row at a time while ($i < $num) { $id=mysql_result($result,$i,"id"); $title=mysql_result($result,$i,"title"); $author=mysql_result($result,$i,"author"); echo "<p>id: $id<br/>Title: $title<br/>Author: $author</p>"; $i++; } ?>

18 PHP/MySQL a simple example (5):


Download ppt "Lecture 4: Introduction to PHP 3 PHP & MySQL"

Similar presentations


Ads by Google