Upload
marilynn-johns
View
226
Download
0
Tags:
Embed Size (px)
Citation preview
IST210 1
PHP and SQL Server: Queries
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
IST210 3
What we have learned
• PHP and SQL connection in last class– http://my.up.ist.psu.edu/zuz22/query.php
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
IST210 5
Prepare Database
• We will use the database in Chapter 3
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
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”
IST210 8
Case 1. Browse a Table (Review)
• http://my.up.ist.psu.edu/zuz22/case1.php
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.
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
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?
IST210 12
Case 2. Browse a Table with Constraint
• http://my.up.ist.psu.edu/zuz22/case2.php
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
IST210 14
Case 2. Code Specificationcase2.php
IST210 15
Case 2. Code Specification (cont.)case2.php
process_case2.php
Any Problem with Case 2?
• Is there anything we can improve in terms of its utility and appearance?
IST210 17
Case 2a. Browse a Table with Constraint – Values from Database
• http://my.up.ist.psu.edu/zuz22/case2a.php
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
IST210 19
Case 2a. Code Specificationcase2a.php
IST210 20
Case 2a. Code Specificationprocess_case2a.php
Same as process_case2.php except “Go back” action
IST210 21
Compare Case 2 and Case 2a
Case 2: manually code all the submit buttons
Case 2a: dynamically generate all the submit buttons
IST210 22
Case 3. Browse a Table with Constraint (Dropdown List)
• http://my.up.ist.psu.edu/zuz22/case3.php
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
IST210 24
Case 3. Code Specificationcase3.php
Compare with case2.php
IST210 25
Case 3. Code Specificationprocess_case3.php
Same as process_case2.php except “Go back” action
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
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?
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
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