Lecture 4 Introduction to PHP 3 PHP My
- Slides: 18
Lecture 4: Introduction to PHP 3 PHP & My. SQL
3 -tier architecture (application view)
Web based 3 -tier architecture
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 o 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. o specific tools and technologies suited to each layer can be deployed (and may evolve at a different pace). o
Web based 3 -tier architecture: tools & technologies Presentation tier – Browser / custom client, Client Side Scripting (Java. Script, Action. Script, VBScript etc. ), Applets. o 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. ) o Data Tier – Database Management System (DBMS) (Oracle, My. SQL, SQL Server, DB 2 etc. ), XMLDB o
Using My. SQL in the persistence tier: My. SQL Strengths o High performance benchmarks very well against commercial dbs o Low-cost no cost under open source licence o Easy to configure and learn easy to set up, SQL compliant o Portable Linux, Unix and Windows versions o Open Source source code available for modification
Tools to create a simple web-editable database QSEE o My. SQL client (or PHPMy. Admin) o PHP Script o
Development Process: Define ER model in QSEE Generate SQL Create Database My. SQL Write Script to process DB
QSEE • Multi-case diagramming tool – All UML diagrams – ++ • Entity-Relationship Diagrams – Generates SQL for various targets (including My. SQL 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 foreign keys
PHPMy. Admin GUI interface to My. SQL server (shares) o GUI runs on stocks (the PHP server) o Full access to a database for o o o o Creating tables Added data Browsing the data Import and Export of tables… Execute SQL queries (DML) or definitions (DML) But. .
PHPMy. Admin Interface
Command line My. SQL Generated SQL comments are rejected by PHPMy. Admin o login to shares directly using putty o change directory to your project directory o Enter: o mysql –p o use database o source proj. sql o
Command line My. SQL
PHP/My. SQL a simple example (1): DB Library - Table Book id title author 1 My. SQL in Nutshell Dyer 2 PHP and My. SQL Ullman 3 Javascript Smith
PHP/My. SQL a simple example (2): <? php // 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");
PHP/My. SQL 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();
PHP/My. SQL 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++; } ? >
PHP/My. SQL a simple example (5):
- 01:640:244 lecture notes - lecture 15: plat, idah, farad
- Php/index.php?id=
- Php php://input
- Introduction to biochemistry lecture notes
- Introduction to psychology lecture
- Introduction to algorithms lecture notes
- Essay structure
- Project procurement management lecture notes
- Lecture about sport
- Lecture on healthy lifestyle
- Makeup lecture meaning
- Life lecture meaning
- Randy pausch last lecture summary
- Tensorflow lecture
- Theology proper lecture notes
- Strategic management lecture
- Geology lecture series
- Social psychology lecture
- In text citation for a lecture