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

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

XMLHttpRequest. CS144: Web Applications

AJAX. Introduction. AJAX: Asynchronous JavaScript and XML

AJAX and PHP AJAX. Christian Wenz,

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

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

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

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

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

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

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

Web Programming/Scripting: PHP and AJAX Refresher

PHP Development - Introduction

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

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

Database Connectivity using PHP Some Points to Remember:

COSC344 Database Theory and Applications PHP & SQL. Lecture 14

Advanced Web Programming Practice Exam II

CSC 405 Computer Security. Web Security

Databases/JQuery AUGUST 1, 2018

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

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

Building Dynamic Forms with XML, XSLT

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

/ Introduction to XML

MySQL: Access Via PHP

Databases and PHP. Accessing databases from PHP

Princess Nourah bint Abdulrahman University. Computer Sciences Department

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

An Introduction to AJAX. By : I. Moamin Abughazaleh

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

Chapter 3: Web Paradigms and Interactivity

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

Lesson 12: JavaScript and AJAX

AJAX: Introduction CISC 282 November 27, 2018

Task 1: JavaScript Video Event Handlers

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

Web Based Conference Management System

wemx WebService V1.0

Comp 519: Web Programming Autumn 2015

Task 1: JavaScript Video Event Handlers

PHP: Hypertext Preprocessor. A tutorial Introduction

MYSQL DATABASE ACCESS WITH PHP

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

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

PHP: Cookies, Sessions, Databases. CS174. Chris Pollett. Sep 24, 2008.

If Only. More SQL and PHP

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

Web Programming Paper Solution (Chapter wise)

Using PHP with MYSQL

PHP Querying. Lecture 21. Robb T. Koether. Hampden-Sydney College. Fri, Mar 2, 2018

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

COMP519: Web Programming Autumn 2015

AJAX: The Basics CISC 282 March 25, 2014

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

AJAX. Ajax: Asynchronous JavaScript and XML *

Locate your Advanced Tools and Applications

IELM 511 Information Systems Design Labs 5 and 6. DB creation and Population

Create-A-Page Design Documentation


Create Basic Databases and Integrate with a Website Lesson 3

Enhancing WebGen5 with Access Control, AJAX Support, and Editable-and-Insertable Select Form.

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

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

CSC Javascript

Options. Real SQL Programming 1. Stored Procedures. Embedded SQL

Web Security. Attacks on Servers 11/6/2017 1

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

AJAX: The Basics CISC 282 November 22, 2017


SCRIPT.ACULO.US - IN-PLACE EDITING

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

Ajax Application Design

Ajax. Ronald J. Glotzbach


LAMP Apps. Overview. Learning Outcomes: At the completion of the lab you should be able to:

CON2DIS 2.0. Ruo Zhang Dhamma Kimpara Anagha Indic

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

PHP. MIT 6.470, IAP 2010 Yafim Landa

Secure Web-Based Systems Fall Test 1

Web Application Security

Pure JavaScript Client

Mount Saint Mary College, Newburgh, NY Internet Programming III - CIT310

AJAX ASYNCHRONOUS JAVASCRIPT AND XML. Laura Farinetti - DAUIN

Web 2.0 and Security

AJAX เสถ ยร ห นตา ส าน กเทคโนโลย สารสนเทศและการส อสาร มหาว ทยาล ยนเรศวร พะเยา

COM1004 Web and Internet Technology

Jquery Ajax Json Php Mysql Data Entry Example

Notes General. IS 651: Distributed Systems 1

SEEM4570 System Design and Implementation. Lecture 6 Game Part II

More loops. Control structures / flow control. while loops. Loops / Iteration / doing things over and over and over and over...

Web Security, Summer Term 2012

MySQL On Crux Part II The GUI Client

A synchronous J avascript A nd X ml

Web Security, Summer Term 2012

CHAPTER 10. Connecting to Databases within PHP

User Interaction: jquery

SETTING UP AND RUNNING A WEB SITE ON YOUR LENOVO STORAGE DEVICE WORKING WITH WEB SERVER TOOLS

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

Transcription:

Use of PHP for DB Connection 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 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 3 4

Steps Create DB pharmacy dbpharmacy.txt localhost/phpmyadmin

DB connection Define a SQL string Execution Data processing 10 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 11 12

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 13 14 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 15 16

<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> 18 <?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>"); 19 Browser Request the php file Display the form only A get request Display the form + order info Asynchronous requests Server Asynchronous Synchronous 20

2 files Html file AJAX Approach 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 ; 21 22 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> 23 24

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>"); 25 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 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 27 28

SQL: Application design 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 29