Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 &14 Intro to SQL Programming Techniques & Web DB + PhP.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Copyright © 2004 Pearson Education, Inc.. Chapter 9 More SQL: Assertions, Views, and Programming Techniques.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
The Web Warrior Guide to Web Design Technologies
CSE 4701 Project-1 Project Phase II Instructions n Download XAMPP l XAMPP includes: Apache, PHP, MySQL, and other goodies. No need to download and install.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Guide To UNIX Using Linux Third Edition
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Overview of Database Languages and Architectures.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
SEMESTER 1, 2013/2014 DB2 APPLICATION DEVELOPMENT OVERVIEW.
JSP Standard Tag Library
CSCI 6962: Server-side Design and Programming
ASP.NET Programming with C# and SQL Server First Edition
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
INTERNET APPLICATION DEVELOPMENT For More visit:
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 9- 1 DATADABASE PROGRAMMING 2Chapter 13 from our text.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Introduction to PHP Advanced Database System Lab no.1.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
Chapter 6 MORE SQL: Assertions, Views, and Programming Techniques Copyright © 2004 Pearson Education, Inc.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Database System Concepts and Architecture.
Introduction to PHP.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
BlackBerry Applications using Microsoft Visual Studio and Database Handling.
IT ELECTIVE 2.  Web server Can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that.
Database Access Using JDBC BCIS 3680 Enterprise Programming.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
JDBC CS 260 Database Systems. Overview  Introduction  JDBC driver types  Eclipse project setup  Programming with JDBC  Prepared statements  SQL.
Unit 1 – Web Concepts Instructor: Brent Presley.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Database Processing Applications Chapter Seven DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 7 th Edition.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
PHP using MySQL Database for Web Development (part II)
Web Database Programming Using PHP
CSE202 Database Management Systems
Web Database Programming Using PHP
JDBC.
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
PHP Introduction.
Intro to PHP & Variables
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Database System Concepts and Architecture.
WEB PROGRAMMING JavaScript.
PHP.
Web DB Programming: PHP
Project Phase II Instructions &Sample Code
Tutorial 6 PHP & MySQL Li Xu
PHP an introduction.
Web Application Development Using PHP
Presentation transcript:

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 &14 Intro to SQL Programming Techniques & Web DB + PhP

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Introduction to SQL Programming Techniques  Database applications  Host language Java, C/C++/C#, COBOL, or some other programming language  Data sublanguage SQL  SQL standards  Continually evolving  Each DBMS vendor may have some variations from standard

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Approaches to Database Programming (cont’d.)  Using a library of database functions  Library of functions available to the host programming language  Application programming interface (API)  Designing a brand-new language  Database programming language designed from scratch  First two approaches are more common

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Impedance Mismatch  Differences between database model and programming language model  Binding for each host programming language  Specifies for each attribute type the compatible programming language types  Cursor or iterator variable  Loop over the tuples in a query result

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Typical Sequence of Interaction in Database Programming  Open a connection to database server  Interact with database by submitting queries, updates, and other database commands  Terminate or close connection to database

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Embedded SQL, Dynamic SQL, and SQLJ  Embedded SQL  C language  SQLJ  Java language  Programming language called host language

Copyright © 2011 Ramez Elmasri and Shamkant Navathe JDBC: SQL Function Calls for Java Programming  JDBC  Java function libraries  Single Java program can connect to several different databases  Called data sources accessed by the Java program  Class.forName("oracle.jdbc.driver.OracleDriver")  Load a JDBC driver explicitly

Copyright © 2011 Ramez Elmasri and Shamkant Navathe

JDBC: SQL Function Calls for Java Programming  Connection object  Statement object has two subclasses:  PreparedStatement and CallableStatement  Question mark ( ? ) symbol  Represents a statement parameter  Determined at runtime  ResultSet object  Holds results of query

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Chapter 14 Outline  A Simple PHP Example  Overview of Basic Features of PHP  Overview of PHP Database Programming

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Web Database Programming Using PHP  Techniques for programming dynamic features into Web  PHP  Open source scripting language  Interpreters provided free of charge  Available on most computer platforms

Copyright © 2011 Ramez Elmasri and Shamkant Navathe A Simple PHP Example  PHP  Open source general-purpose scripting language  Comes installed with the UNIX operating system

Copyright © 2011 Ramez Elmasri and Shamkant Navathe A Simple PHP Example (cont’d.)  DBMS  Bottom-tier database server  PHP  Middle-tier Web server  HTML  Client tier

Copyright © 2011 Ramez Elmasri and Shamkant Navathe A Simple PHP Example (cont’d.) Client Tier Middle-tier Web Server Database Server

Copyright © 2011 Ramez Elmasri and Shamkant Navathe

A Simple PHP Example (cont’d.)  Example Figure 14.1(a)  PHP script stored in:   <?php  PHP start tag  ?>  PHP end tag  Comments: // or /* */

Copyright © 2011 Ramez Elmasri and Shamkant Navathe A Simple PHP Example (cont’d.)  $_POST  Auto-global predefined PHP variable  Array that holds all the values entered through form parameters  Arrays are dynamic  Long text strings  Between opening <<<_HTML_ and closing _HTML_;

Copyright © 2011 Ramez Elmasri and Shamkant Navathe A Simple PHP Example (cont’d.)  PHP variable names  Start with $ sign

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Overview of Basic Features of PHP  Illustrate features of PHP suited for creating dynamic Web pages that contain database access commands

Copyright © 2011 Ramez Elmasri and Shamkant Navathe PHP Variables, Data Types, and Programming Constructs  PHP variable names  Start with $ symbol  Can include characters, letters, and underscore character ( _ )  Main ways to express strings and text  Single-quoted strings  Double-quoted strings  Here documents  Nowdoc (PHP and later)

Copyright © 2011 Ramez Elmasri and Shamkant Navathe PHP Variables, Data Types, and Programming Constructs (cont’d.)  Period (.) symbol  String concatenate operator  Single-quoted strings  Literal strings that contain no PHP program variables, no parsing/escaping except \’, \\  Double-quoted strings and here documents  Values from variables need to be interpolated into string

Copyright © 2011 Ramez Elmasri and Shamkant Navathe PHP Variables, Data Types, and Programming Constructs (cont’d.)  Numeric data types  Integers and floating points  Programming language constructs  For-loops, while-loops, and conditional if- statements  Boolean expressions

Copyright © 2011 Ramez Elmasri and Shamkant Navathe PHP Variables, Data Types, and Programming Constructs (cont’d.)  Comparison operators  == (equal), != (not equal), <> (not equal) > (greater than), >= (greater than or equal), < (less than), and <= (less than or equal)  ===, !== (equal and not equal without type juggling)  Type juggling will convert strings to numbers if possible

Copyright © 2011 Ramez Elmasri and Shamkant Navathe PHP Arrays  Database query results  Two-dimensional arrays  First dimension representing rows of a table  Second dimension representing columns (attributes) within a row  Main types of arrays:  Numeric and associative

Copyright © 2011 Ramez Elmasri and Shamkant Navathe PHP Arrays (cont’d.)  Numeric array  Associates a numeric index with each element in the array  Indexes are integer numbers Start at zero Grow incrementally  Associative array  Provides pairs of (key => value) elements

Copyright © 2011 Ramez Elmasri and Shamkant Navathe PHP Arrays (cont’d.)

Copyright © 2011 Ramez Elmasri and Shamkant Navathe PHP Arrays (cont’d.)  Techniques for looping through arrays in PHP  Count function  Returns current number of elements in array  Sort function  Sorts array based on element values in it

Copyright © 2011 Ramez Elmasri and Shamkant Navathe PHP Functions  Functions  Define to structure a complex program and to share common sections of code  Arguments passed by value  Examples to illustrate basic PHP functions  Figure 14.4  Figure 14.5

Copyright © 2011 Ramez Elmasri and Shamkant Navathe

PHP Functions (cont’d.)

Copyright © 2011 Ramez Elmasri and Shamkant Navathe PHP Server Variables and Forms  Built-in entries  $_SERVER auto-global built-in array variable  Provides useful information about server where the PHP interpreter is running

Copyright © 2011 Ramez Elmasri and Shamkant Navathe PHP Server Variables and Forms (cont’d.)  Examples: $_SERVER['SERVER_NAME'] $_SERVER['REMOTE_ADDRESS'] $_SERVER['REMOTE_HOST'] $_SERVER['PATH_INFO'] $_SERVER['QUERY_STRING'] $_SERVER['DOCUMENT_ROOT']  $_POST  Provides input values submitted by the user through HTML forms specified in tag

Copyright © 2011 Ramez Elmasri and Shamkant Navathe PHP Including Files  include “./path/to/file.php”;  Attempts to copy the contents of file.php to the specified path  No code included if not found, but script continues execution  include_once  Equivalent to include but checks to see if the file has already been included first  If file is present, execution continues

Copyright © 2011 Ramez Elmasri and Shamkant Navathe PHP Including Files (cont’d.)  require “./path/to/file.php”;  Attempts to copy the contents of file.php to the specified path  If file is not found, PHP throws an error and execution stops  require_once “./path/to/file.php”;  Equivalent to require but checks to see if the file has already been included first  If file is present, execution continues

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Object Oriented PHP  Use the class keyword to declare a new class  Declare variables private/public/protected  Declare a new object with the new keyword  Use -> to access functions  Eg. $some_object->my_function();

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Object Oriented PHP (cont’d.)

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Debugging PHP  var_dump($var)  Prints the content of the variable $var into the output  Also prints variable type information  Prints out all values in nested arrays/objects  Third party libraries  Kint prints out formatted info in a tree-like format

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Debugging PHP (cont’d.)

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Overview of PHP Database Programming  PEAR DB library  Part of PHP Extension and Application Repository (PEAR)  Provides functions for database access

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Connecting to a Database  Library module DB.php must be loaded  DB library functions accessed using DB::  DB::connect('string')  Function for connecting to a database  Format for 'string' is: ://

Copyright © 2011 Ramez Elmasri and Shamkant Navathe

Connecting to a Database (cont’d.)  Query function  $d->query takes an SQL command as its string argument  Sends query to database server for execution  $d–>setErrorHandling(PEAR_ERROR_DIE)  Terminate program and print default error messages if any subsequent errors occur

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Collecting Data from Forms and Inserting Records  Collect information through HTML or other types of Web forms  Create unique record identifier for each new record inserted into the database  PHP has a function $d–>nextID to create a sequence of unique values for a particular table  Placeholders  Specified by ? symbol

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Retrieval Queries from Database Tables  $q  Query result  $q->fetchRow() retrieve next record in query result and control loop  $d->getAll  Holds all the records in a query result in a single variable called $allresult

Copyright © 2011 Ramez Elmasri and Shamkant Navathe

Summary  PHP scripting language  Very popular for Web database programming  PHP basics for Web programming  Data types  Database commands include:  Creating tables, inserting new records, and retrieving database records

Copyright © 2011 Ramez Elmasri and Shamkant Navathe NEED TO ADD – USING REST APIs SLIDES

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Project Phase II Instructions  Download XAMPP  XAMPP includes: Apache, PHP, MySQL, and other goodies. No need to download and install them separately, XAMPP does it all.  Download:  FAQs (Includes instructions on how to install it and set it up): Windows FAQs: OSX FAQs: Linux FAQs:

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Project Phase II Instructions  Download Aptana Studio  Aptana Studio is a web development IDE rooted on Eclipse. You can use your preferred IDE for the project, it does not need to be Aptana.  Download:  You can download Aptana Studio 2, 3 or either as an Eclipse plugin. For the instructions on this guide, we will use the standalone (not the Eclipse plugin) version of Aptana Studio 3.

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Project Phase II Instructions  Sample API (Slim Framework)  Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.  Slim Framework documentation:  See : TBD  Sample GUI Web-App (for CRUD operations)  A sample CRUD (Create, Read, Update, Delete) web- app that interfaces with the MySQL database to use.  See : TBD

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Setting up a Sample DB  XAMPP bundles in PhpMyAdmin (

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Set PhpMyAdmin web-app  Go to:  If you don’t use Port 80 – Use where {yourport} is the custom port.

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Setting up the Sample API  Add sample_api, to you XAMPP’s htdocs folder  With sample_api in place:  Open Aptana Studio (or your IDE)  Click File -> Import  Select Existing Folder as New Project  Select a folder. Navigate to your C:/xampp/htdocs/sample_api folder  Give the project a name  Select PHP and Web - Primary as the project types  Click on Finish

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Sample_gui – customers.php

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Sample_gui – customers.php

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Sample_api – index.php

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Sample_api – index.php

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Sample_api – index.php

Copyright © 2011 Ramez Elmasri and Shamkant Navathe Sample_api – index.php