Use of PHP for DB Connection. Middle and Information Tier

Similar documents
Use of PHP for DB Connection. Middle and Information Tier. Middle and Information Tier

XMLHttpRequest. CS144: Web Applications

AJAX and PHP AJAX. Christian Wenz,

AJAX. Introduction. AJAX: Asynchronous JavaScript and XML

A.A. 2008/09. What is Ajax?

Development Technologies. Agenda: phpmyadmin 2/20/2016. phpmyadmin MySQLi. Before you can put your data into a table, that table should exist.

Introduction to InfoSec SQLI & XSS (R10+11) Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)

AJAX. Lecture 26. Robb T. Koether. Fri, Mar 21, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) AJAX Fri, Mar 21, / 16

Best Practices for Embedded User Assistance

AJAX(Asynchronous Javascript + XML) Creating client-side dynamic Web pages

CITS1231 Web Technologies. Ajax and Web 2.0 Turning clunky website into interactive mashups

Networks and Web for Health Informatics (HINF 6220) Tutorial 13 : PHP 29 Oct 2015

Table of Contents. 1. A Quick Overview of Web Development...1 EVALUATION COPY


CSC 405 Computer Security. Web Security

An Introduction to AJAX. By : I. Moamin Abughazaleh


Chapter 3: Web Paradigms and Interactivity

Web Programming/Scripting: PHP and AJAX Refresher

Contents. Demos folder: Demos\14-Ajax. 1. Overview of Ajax. 2. Using Ajax directly. 3. jquery and Ajax. 4. Consuming RESTful services

PHP Development - Introduction

CSE 130 Programming Language Principles & Paradigms Lecture # 20. Chapter 13 Concurrency. + AJAX Discussion

function initcompleted() { settimeout('fbegin1()',300); } var allstudents = '';

Databases and PHP. Accessing databases from PHP

COSC344 Database Theory and Applications PHP & SQL. Lecture 14

Web Programming Paper Solution (Chapter wise)

Web Application Security

wemx WebService V1.0

Hello everyone! Page 1. Your folder should look like this. To start with Run your XAMPP app and start your Apache and MySQL.

AJAX: Introduction CISC 282 November 27, 2018

Databases/JQuery AUGUST 1, 2018

Advanced Web Programming with JavaScript and Google Maps. Voronezh State University Voronezh (Russia) AJAX. Sergio Luján Mora

Ajax- XMLHttpResponse. Returns a value such as ArrayBuffer, Blob, Document, JavaScript object, or a DOMString, based on the value of

AJAX. Lab. de Bases de Dados e Aplicações Web MIEIC, FEUP 2010/11. Sérgio Nunes

PHP Online Training. PHP Online TrainingCourse Duration - 45 Days. Call us: HTML

Advanced Web Programming Practice Exam II

Phase I. Initialization. Research. Code Review. Troubleshooting. Login.aspx. M3THOD, LLC Project Documentation

AJAX. Ajax: Asynchronous JavaScript and XML *

Create-A-Page Design Documentation

Task 1: JavaScript Video Event Handlers

Ajax Application Design

Creating an Online Catalogue Search for CD Collection with AJAX, XML, and PHP Using a Relational Database Server on WAMP/LAMP Server

Pure JavaScript Client

Database Connectivity using PHP Some Points to Remember:

/ Introduction to XML

Lesson 12: JavaScript and AJAX

Building Dynamic Forms with XML, XSLT

Web Based Conference Management System

TIME SCHEDULE MODULE TOPICS PERIODS. HTML Document Object Model (DOM) and javascript Object Notation (JSON)

Jquery Ajax Json Php Mysql Data Entry Example

PHP: Hypertext Preprocessor. A tutorial Introduction

It is highly recommended that you are familiar with HTML and JavaScript before attempting this tutorial.

Contents. Acknowledgments

AJAX: The Basics CISC 282 March 25, 2014

Task 1: JavaScript Video Event Handlers

School of Information and Computer Technology Sirindhorn International Institute of Technology Thammasat University

Comp 519: Web Programming Autumn 2015

Ajax. Ronald J. Glotzbach

COMP519: Web Programming Autumn 2015

A synchronous J avascript A nd X ml

Using AJAX to Easily Integrate Rich Media Elements

1. Introduction. 2. Online life history calendar. Jumping around in Blaise IS. Maurice Martens, CentERdata

PHP for PL/SQL Developers. Lewis Cunningham JP Morgan Chase

CSC Javascript


Web Security, Summer Term 2012

Professional Course in Web Designing & Development 5-6 Months

Web Security, Summer Term 2012

Networking & The Web. HCID 520 User Interface Software & Technology

MySQL: Access Via PHP

quiz 1 details wed nov 17, 1pm see handout for locations covers weeks 0 through 10, emphasis on 7 onward closed book bring a , 2-sided cheat she

CON2DIS 2.0. Ruo Zhang Dhamma Kimpara Anagha Indic

Princess Nourah bint Abdulrahman University. Computer Sciences Department

AJAX: The Basics CISC 282 November 22, 2017

Using PHP with MYSQL

WebApp development. Outline. Web app structure. HTML basics. 1. Fundamentals of a web app / website. Tiberiu Vilcu

Ajax. David Matuszek's presentation,

Oracle WebLogic Portal

Specification on tables display(ergonomics) in PhpPgAdmin 4.2.3

Ajax UNIX MAGAZINE if0505.pdf. (86) Ajax. Ajax. Ajax (Asynchronous JavaScript + XML) Jesse James Garrett Web 1. Web.

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

CIW 1D CIW JavaScript Specialist.

Front-end / Back-end. How does your application communicate with services?

All India Council For Research & Training

Web Application Development (WAD) V th Sem BBAITM (Unit 4) By: Binit Patel

Networking & The Web. HCID 520 User Interface Software & Technology

Chapter 1 Introduction to Computers and the Internet

Project. Minpeng Zhu

MYSQL DATABASE ACCESS WITH PHP

ajax1.html 1/2 lectures/7/src/ ajax1.html 2/2 lectures/7/src/

Notes General. IS 651: Distributed Systems 1

! The final is at 10:30 am, Sat 6/4, in this room. ! Open book, open notes. ! No electronic devices. ! No food. ! Assignment 7 due 10pm tomorrow

jmaki Overview Sang Shin Java Technology Architect Sun Microsystems, Inc.

Introduction to Web Concepts & Technologies

Lecture 13: MySQL and PHP. Monday, March 26, 2018

INTRODUCTION TO.NET. Domain of.net D.N.A. Architecture One Tier Two Tier Three Tier N-Tier THE COMMON LANGUAGE RUNTIME (C.L.R.)

Setting Up a Development Server What Is a WAMP, MAMP, or LAMP? Installing a WAMP on Windows Testing the InstallationAlternative WAMPs Installing a

Module 5 JavaScript, AJAX, and jquery. Module 5. Module 5 Contains 2 components

Module7: AJAX. Click, wait, and refresh user interaction. Synchronous request/response communication model. Page-driven: Workflow is based on pages

XML Processing & Web Services. Husni Husni.trunojoyo.ac.id

Transcription:

Client: UI HTML, JavaScript, CSS, XML Use of PHP for DB Connection Middle Get all books with keyword web programming PHP Format the output, i.e., data returned from the DB SQL DB Query Access/MySQL 1 2 Middle and Information Tier PHP: built in library functions for interfacing with the mysql database management system $id = mysqli_connect(string hostname, string username, string password, string db) Connection to the MySQL server Return false if fails $result = $id->query(string query) Execute a SQL query: return a result handle that will be used to fetch the result 3 4

Steps Middle and Information Tier PHP: built in function for mysql $result->data_seek(0); Go to the first row of the result $row=$result->fetch_assoc() Fetch the row of the results Combine with a while loop to read all rows $id->close() Close the connection Create DB pharmacy dbpharmacy.txt localhost/phpmyadmin 5

DB connection Define a SQL string Execution Data processing 11 12

Exercise Modify previous examples to show the following info: Database Modification: Insert Syntax: INSERT INTO table_name VALUES (value1, value2,.) Step: DB connection Define a string containing the SQL command Execute the sql statement 13 14 Database Modification: Modify Syntax: UPDATE table_name SET column_name_i = new_value where column_name_j=some_value Step: DB connection Define a string containing the SQL command Execute the sql statement AJAX and DB 15 16

AJAX and Database Display info in one page Display info whenever the info is received A Possible Approach Using get method If there is a salesperson s name in the URL, then display the required information Otherwise, display the form only Require HTML or PHP file? Two parts: a form to be displayed A db query to display the required info 17 18 <form method="get" action= query2.php"> <p> Select a salesperson to display the info: <select name="select"> <option value="abel" selected="selected"> Abel </option> <option value="baker"> Baker </option> <option value="jones"> Jones </option> <option value="kobad"> Kobad </option> <option value="murphy"> Murphy </option> <option value="zenith"> Zenith </option> </select> </p> <p> <input type="submit" value="query" /> </p> </form> 20

<?php if (isset($_get["select"]) and $_GET["select"]!=NULL) { $q = $_GET["select"]; $conn = mysqli_connect("localhost", "root", "","pharmacy"); if ($conn->connect_error) { echo "Unable to connect to database"; exit; print("<h1> Sales person: ". $q. "</h1>"); $query1 = "select salary from salesperson where SalesName= '". $q. "'"; $result1 = $conn->query($query1); if (!$result1) die("no information"); $result1->data_seek(0); while ($row=$result1->fetch_assoc()) { print("<h2> Salary: ". $row["salary"]. "</h2>"); 21 Browser Request the php file Display the form only A get request Display the form + order info Asynchronous requests Server Asynchronous Synchronous 22 AJAX Approach 2 files Html file A form A JavaScript function Make asynchronous connection Call to the php file, display the information when it is ready Php file Query the db to get the desired info <script type="text/javascript"> var xmlhttp; function showinfo(str) { try{ xmlhttp = new XMLHttpRequest(); catch (e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); catch (e) { try{ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); catch (e){ alert( Error!"); return ; 23 24

var url = "phpsales.php?q=" + str; xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate == 4) { disinfo.innerhtml = xmlhttp.responsetext; xmlhttp.open("get", url, true); xmlhttp.send(null); </script> <form> <p> Select a salesperson to display the info: <select name="select" onchange="showinfo(this.value)"> <option value="abel" selected="selected"> Abel </option> <option value="baker"> Baker </option> <option value="jones"> Jones </option> <option value="kobad"> Kobad </option> <option value="murphy"> Murphy </option> <option value="zenith"> Zenith </option> </select> </p> </form> <div id="disinfo"> </div> 25 26 display.php $q = $_GET["select"]; $conn = mysqli_connect("localhost", "root", "","pharmacy"); if ($conn->connect_error) { echo "Unable to connect to database"; exit; print("<h1> Sales person: ". $q. "</h1>"); $query1 = "select salary from salesperson where SalesName= '". $q. "'"; $result1 = $conn->query($query1); if (!$result1) die("no information"); $result1->data_seek(0); while ($row=$result1->fetch_assoc()) { print("<h2> Salary: ". $row["salary"]. "</h2>"); 27

POST var url = display.php"; var queryvalue = encodeuricomponent(str); var parameters = "q="+queryvalue; xmlhttp.open("post", url, true); xmlhttp.setrequestheader("content-type", "application/x-www-form-urlencoded"); xmlhttp.send(parameters); Application design Design application in tiers Each tier can be run a separate machine, allowing for improved processing performance Promote scalability Ease long term maintenance requirements for your code Client tier Middle tier Information tier 29 30 Application design PHP: Server side scripting language SQL: Language used to query the relational database WHERE, ORDER BY, COUNT(*) Processing in PHP or SQL? Sorting, pattern matching in records Application design SQL: Language specifically designed to query and retrieve data from your tables!! Filter out unnecessary data using SQL, leaving a relevant data set for PHP to work with Selecting statement, WHERE condition ORDER BY: sorting FASTER CODE, NETWORK LOAD 31 32

Setting up a site Components Design the web documents Client side techniques: CSS, JavaScript, DHTML Server side techniques Scripting languages, how to access database Administrating a web site: IMPORTANT Difficult to keep all documents/information up to date easily Information Maintenance of a content-driven site can be a real pain Solution: database-driven site design Complete separation between the site design and the content you want to present Don t write an HTML file for every page of your site Write a page for each kind of information you want to present 33 34 Idea Model Database: content of the site Dynamically pulled from the database to create web pages Template HTML page: For each kind (type) of information browser Web server PHP file MySQ L On the visitor s end: Expects to view a standard HTML web page On the other end Have a database that only understands how to respond to SQL queries PHP scripting language go-between that speaks both languages 35 36