PHP AND SQL SERVER: QUERIES IST 210: Organization of Data IST210 1.

Slides:



Advertisements
Similar presentations
Stored procedures and views You can see definitions for stored procedures and views in the demo databases but you can’t change them. For views, expand.
Advertisements

WebGoat & WebScarab “What is computer security for $1000 Alex?”
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Laboratory 1: Introduction to Relational.
Multiple Tiers in Action
Structured Query Language (SQL)
PHP Scripts HTML Forms Two-tier Software Architecture PHP Tools.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
MIS2502: Data Analytics MySQL and SQL Workbench David Schuff
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.
PHP and SQL Server: Queries IST2101. Project Report 4 SQL Queries Due Sunday, 4/5 at 11:59pm Instructions on how to access team webspace and SQL database.
Web-based Document Management System By Group 3 Xinyi Dong Matthew Downs Joshua Ferguson Sriram Gopinath Sayan Kole.
CONFIGURING WINDOWS SERVER MIS 424 Professor Sandvig.
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Thursday, October 18, 2012 Session 7: PHP.
1 Insert, Update and Delete Queries. 2 Return to you Address Book database. Insert a record.
JavaScript & jQuery the missing manual Chapter 11
Microsoft Azure Introduction ISYS 512. Microsoft Azure Microsoft Azure is a cloud.
Server-side Scripting Powering the webs favourite services.
Analysis of SQL injection prevention using a proxy server By: David Rowe Supervisor: Barry Irwin.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
Universiti Utara Malaysia Chapter 3 Introduction to ASP.NET 3.5.
Introduction to MySQL Lab no. 10 Advance Database Management System.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Mini Group Presentations: php by Veronica Black + Jia Xu.
MyBLAST standalone installation Lab of Systems Biology & Network Biology website Download link. 1.Click the Download link.
Structured Query Language SQL-I
Structured Query Language (SQL) IST2101. Structured Query Language – Acronym: SQL – Pronounced as “S-Q-L” [“Ess-Que-El”] – Originally developed by IBM.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn.
HTML Table and PHP Array
CHAPTER 9 PHP AND MYSQL. A POSSIBLE SITE CONFIGURATION Application Folder index.php includes (folder)header.phpfooter.phpstyle.cssmodel (folder)mysqli_connect.php.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
STRUCTURED QUERY LANGUAGE SQL-II IST 210 Organization of Data IST210 1.
Course FAQ’s I do not have any knowledge on SQL concepts or Database Testing. Will this course helps me to get through all the concepts? What kind of.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
PHP and SQL Server: Connection IST2101. Typical web application interaction (php, jsp…) database drivers 2IST210.
PHP and SQL Server: Queries IST2101. Steps to Design PHP Pages to Answer User Queries 1.Query generation – What SQL query do we need to retrieve the desired.
Connect to your SQL Server  Log on an IST Windows machine  If not in the lab, use remote desktop 
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Database Access Control IST2101. Why Implementing User Authentication? Remove a lot of redundancies in duplicate inputs of database information – Your.
Agenda for Class 2/20/2014 Introduce Microsoft’s SQL Server database management system. Use the lab to discuss how to CREATE, DROP and populate (INSERT)
How Web Database Architectures Work CPS181s April 8, 2003.
 Before you continue you should have a basic understanding of the following:  HTML  CSS  JavaScript.
Courses NumNameDesc Record Field Table Credits. “PROJECT”“SELECT” Operators on Tables.
SQL Query Analyzer. Graphical tool that allows you to:  Create queries and other SQL scripts and execute them against SQL Server databases. (Query window)
SSMS SQL Server Management System. SQL Server Microsoft SQL Server is a Relational Database Management System (RDBMS) Relational Database Management System.
PHP ARRAY AND HTML TABLE IST 210 Organization of Data IST210 1.
Chapter 9 Working with Databases. Copyright © 2011 Pearson Addison-Wesley Introduction In this chapter you will learn: – Basic database concepts – How.
MYSQL AND MYSQL WORKBENCH MIS2502 Data Analytics.
Structured Query Language SQL-II IST 210 Organization of Data IST2101.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
PHP Array and HTML Table IST 210 Organization of Data IST2101.
Structured Query Language SQL-I IST 210 Organization of Data IST2101.
A Simple Website using Cascading Style Sheets (CSS) IST2101.
DATABASE ACCESS CONTROL IST Question Almost every PHP page needs to interact with database, does that mean sqlUsername and sqlPassword need to be.
PHP and SQL Server: Connection IST 210: Organization of Data IST2101.
PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used, free, and efficient alternative.
1 Adding a Model. We have created an MVC web app project Added a controller class. Added a view class. Next we will add some classes for managing movies.
PHP AND SQL SERVER: CONNECTION IST 210: Organization of Data IST210 1.
Migrating Wordpress Migrating Wordpress can sometimes get more complicated as it should. There is no plugin that does this for you, the best way is to.
DBMS Programs MS SQL Server & MySQL
Introduction to Dynamic Web Programming
Hillsborough Community College
Web Design and Development
Database Driven Websites
20761B 12: Using Set Operators Module 12   Using Set Operators.
Tutorial 6 PHP & MySQL Li Xu
Presentation transcript:

PHP AND SQL SERVER: QUERIES IST 210: Organization of Data IST210 1

Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST210 2 Client (PC) Web Server DBMS PHP is run on the web server Browser Microsoft SQL Management Studio Our technical setting

What we have learned PHP and SQL connection IST210 3

4 PHP SQL Example Query Which table to query: What attributes to query (separated by,):

IST210 5 <?php $server = "mssql.up.ist.psu.edu"; $sqlUsername = "Your-SQL-Username"; $sqlPassword = "Your-SQL-Password"; $databaseName = "Your-PSU-ID"; $connectionInfo = array('Database'=>$databaseName, 'UID'=>$sqlUsername, 'PWD'=>$sqlPassword, 'Encrypt'=>'0', 'ReturnDatesAsStrings'=>true ); $connection = sqlsrv_connect( $server, $connectionInfo ) or die("ERROR: database parameters are not correct");

IST210 6 if (!empty($_POST['table'])) { // get the table name $table = $_POST['table']; if (!empty($_POST['attr'])) { $attr = $_POST['attr']; $query = "SELECT $attr FROM $table"; } else { // prepare SQL query $query = "SELECT * FROM $table"; } // print the query echo "Query: ".$query." ";

IST210 7 // Execute SQL query $result = sqlsrv_query($connection, $query) or die( "ERROR: Query is wrong"); echo " "; // fetch attribute names foreach( sqlsrv_field_metadata($result) as $fieldMetadata) echo " ".$fieldMetadata['Name']." "; echo " "; // fetch rows in the table while( $row = sqlsrv_fetch_array( $result, SQLSRV_FETCH_ASSOC) ) { echo " \n"; foreach ($row as $cell) { echo " $cell "; } echo " \n"; } echo " ";

Today’s Objectives Answer different queries from PHP Cases: (challenging) exercise (challenging) exercise IST210 8

Prepare Database We will use the database in Chapter 3 If you delete the database in Chapter 3, download the SQL script and create the database again (see the last few slides) IST210 9

Case 1. Submit – Manual Coding IST210 10

Case 1. Code Specification IST case1.php

Case 1. Code Specification (cont.) IST case1.php process_case1.php

Problem with Manual Coding Cannot dynamically update information What if we delete some departments in the database? We need to change PHP page! Bad! Database and webpages are separate layers Easy to make bugs “administration” is misspelled Solution? Dynamically generate the departments by querying the data from the database! IST210 13

Case 1a. Submit – Automatic Coding IST210 14

Case 1a. Code Specification IST case1a.php Get the department names from database Dynamicall y generate the submit buttons

Compare Case 1 and Case 1a IST Case 1: manually code all the submit buttons Case 2a: automatically generate all the submit buttons Important lines!

Case 1a. Code Specification IST process_case1a.php Same as process_case1.php except “Go back” action

Case 2. Dropdown List – Manual Coding IST210 18

Case 2. Code Specification IST case2.php

Case 2. Code Specification (Cont.) IST Process_case2.php

Case 2a. Dropdown List – Automatic Coding IST210 21

Case 2a. Code Specification IST case2a.php

Compare case2.php and case2a.php IST Case2.php Manual coding Case2a.php Automatic coding

In-Class Exercise Get the cases run on your webspace IST210 24

Step 1 Download the cases.zip from wikipage Unzip it, you will 8 PHP files case1.php, process_case1.php case1a.php, process_case1a.php case2.php, process_case2.php case2a.php, process_case2a.php Copy all the files to your webspace IST210 25

Step 2 Open php files using NotePad++ and modify the data information IST Input your own information

Step 3 Visit your php page and query your database IST210 27

Prepare Database If you don’t have the tables and data in your database… IST210 28

Prepare Database We will use the database in Chapter 3 IST210 29

Prepare Database (cont.) Log on an IST Windows machine If not in the lab, use remote desktop Run the SQL Server application Start  Application Development and Management  Microsoft SQL Server 2014  SQL Server 2014 Management Studio Parameters Server Type: Database Engine Server Name: upsql Authentication: Windows Authentication Alternate Authentication (connect to the same database): SQL Server Authentication Get your SQL account: Hit “Connect” IST210 30

Prepare Database (cont.) Download scripts on our website Open them in SQL management studio and run them. 1. Delete all the tables 2. Create new database 3. Insert data IST210 31

Prepare Database (cont.) You should now have 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 32