+ All Categories
Home > Documents > PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the...

PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the...

Date post: 23-Dec-2015
Category:
Upload: marilynn-johns
View: 221 times
Download: 0 times
Share this document with a friend
Popular Tags:
29
PHP and SQL Server: Queries IST210 1
Transcript
Page 1: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 1

PHP and SQL Server: Queries

Page 2: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 2

Three-Tier Architecture

• Three-tier architecture means that the Web server and the DBMS are on separate servers

Client (PC) Web Server DBMS

PHP is run on the web server

Browser Microsoft SQL Management Studio

Our technical setting

Page 3: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 3

What we have learned

• PHP and SQL connection in last class– http://my.up.ist.psu.edu/zuz22/query.php

Page 4: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 4

Today’s Objectives

• Answer different queries from PHP• Cases:– http://my.up.ist.psu.edu/zuz22/case1.php

• Review exercise

– http://my.up.ist.psu.edu/zuz22/case2.php– http://my.up.ist.psu.edu/zuz22/case2a.php– http://my.up.ist.psu.edu/zuz22/case3.php– http://my.up.ist.psu.edu/zuz22/case3a.php

• Lab exercise

Page 5: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 5

Prepare Database

• We will use the database in Chapter 3

Page 6: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 6

Prepare Database• Log into your SQL Server application and check whether you

already have these 4 tables• If not, do the following…

– Delete any tables (assignment, project, employee, and department) you have in your database• Right click table, click “delete”• Because of the referential integrity constraints, you need to follow certain

order to delete the tables: assignment project employee department

– Create new database• Download SQL-Create-Tables.sql from SQL (Ch. 3) class on course website and

run it

– Insert data• Download SQL-Insert-Data.sql from SQL (Ch. 3) class on course website and run

it

Page 7: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 7

Prepare Database (cont.)

• You should now have the 4 tables in your database– If not, right click Tables, and

click “refresh”• Check whether you already

have the data in your tables– Right click on a table and click

“Select Top 1000 Rows”

Page 8: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 8

Case 1. Browse a Table (Review)

• http://my.up.ist.psu.edu/zuz22/case1.php

Page 9: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 9

Case 1. Get it run on your webspace (Step 1)

• Download week11-3-cases.zip from wikipage.

• Unzip it, you will have 8 PHP files. Copy all the files to your webspace.

Page 10: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 10

Case 1. Get it run on your webspace (Step 2)

• Open process_case1.php from NotePad++ and modify the information

Input your own information

Page 11: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 11

Case 1. Debugging

Visit your php page and query your database– http://my.up.ist.psu.edu/YourPSUID/case1.php

What problems do you see? How to fix them?

Page 12: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 12

Case 2. Browse a Table with Constraint

• http://my.up.ist.psu.edu/zuz22/case2.php

Page 13: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 13

Case 2. Get it run on your webspace

• Follow the steps as Case 1• Open process_case2.php and add your database

information to the file• Visit your PHP page from Internet:

• http://my.up.ist.psu.edu/YourPSUID/case2.php

Page 14: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 14

Case 2. Code Specificationcase2.php

Page 15: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 15

Case 2. Code Specification (cont.)case2.php

process_case2.php

Page 16: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

Any Problem with Case 2?

• Is there anything we can improve in terms of its utility and appearance?

Page 17: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 17

Case 2a. Browse a Table with Constraint – Values from Database

• http://my.up.ist.psu.edu/zuz22/case2a.php

Page 18: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 18

Case 2a. Get it run on your webspace

• Follow the steps as Case 1• Open case2a.php and process_case2a.php and add your

database information to both files• Visit your PHP page from Internet:

• http://my.up.ist.psu.edu/YourPSUID/case2a.php

Page 19: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 19

Case 2a. Code Specificationcase2a.php

Page 20: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 20

Case 2a. Code Specificationprocess_case2a.php

Same as process_case2.php except “Go back” action

Page 21: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 21

Compare Case 2 and Case 2a

Case 2: manually code all the submit buttons

Case 2a: dynamically generate all the submit buttons

Page 22: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 22

Case 3. Browse a Table with Constraint (Dropdown List)

• http://my.up.ist.psu.edu/zuz22/case3.php

Page 23: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 23

Case 3. Get it run on your webspace

• Follow the steps as Case 1• Open process_case3.php and add your database

information to the file• Visit your PHP page from Internet:

• http://my.up.ist.psu.edu/YourPSUID/case3.php

Page 24: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 24

Case 3. Code Specificationcase3.php

Compare with case2.php

Page 25: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 25

Case 3. Code Specificationprocess_case3.php

Same as process_case2.php except “Go back” action

Page 26: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 26

Case 3a. Lab Exercise

• Now we want to merge the improvements we made in Case 2a (values retrieved from database) and Case 3 (using dropdown list) to create a better webpage.

• http://my.up.ist.psu.edu/zuz22/case3a.php

Page 27: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 27

Case 3a. Lab Exercise Hint 1

• Create case3a.php in your webspace, copy from case2a.php and modify it

Action to which PHP page?

Page 28: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 28

Case 3a. Lab Exercise Hint 2

• Modify your case3a.php

How to modify this segment to echo something like a dropdown list?

Case2a.php will generate this

Page 29: PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.

IST210 29

Case 3a. Lab Exercise Hint 3

• Create process_case3a.php, copy from process_case2a.php and modify it

This is the only place you need to modify


Recommended