Web Database Programming Connecting Database to Web.

Slides:



Advertisements
Similar presentations
PHP: Date() Function The PHP date() function formats a timestamp to a more readable date and time.
Advertisements

PHP II Interacting with Database Data. The whole idea of a database-driven website is to enable the content of the site to reside in a database, and to.
PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect.
Keys, Referential Integrity and PHP One to Many on the Web.
PHP and MySQL Database. Connecting to MySQL Note: you need to make sure that you have MySQL software properly installed on your computer before you attempt.
PHP Week 11 INFM 603. Thinking About PHP Local vs. Web-server-based display HTML as an indirect display mechanism “View Source” for debugging –But not.
NMED 3850 A Advanced Online Design February 25, 2010 V. Mahadevan.
Intermediate PHP & MySQL
Figure 1. Hit analysis in 2002 of database-driven web applications Hits by Category in 2002 N = 73,873 Results Reporting 27% GME 26% Research 20% Bed Availability.
02/09/2015 Intro PHP & MySQL 1 Helen Hastie Room: EMB244 Material available on Vision (modified from slides by Monica Farrow) F27DB Introduction.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
What is MySQL? MySQL is a database. The data in MySQL is stored in database objects called tables. A table is a collections of related data entries and.
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
08/09/2015 Intro PHP & MySQL 1 Helen Hastie Room: EM2.44 Material available on Vision (modified from slides by Monica Farrow) F27DB Introduction.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
INTERNET APPLICATION DEVELOPMENT For More visit:
Create an online booking system (login/registration)
Server-side Scripting Powering the webs favourite services.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
PHP meets MySQL.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Introduction to MySQL Lab no. 10 Advance Database Management System.
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.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
1. Connecting database from PHP 2. Sending query 3. Fetching data 4. Persistent connections 5. Best practices.
Database Access with PHP and MySQL CS356 Examples from Web Database Applications, by Hugh E. Williams & David Lane, O'Reilly, 2002.
Website Development with PHP and MySQL Saving Data.
Internet Information Systems Writing to Databases and Amending Data.
CHAPTER 9 PHP AND MYSQL. A POSSIBLE SITE CONFIGURATION Application Folder index.php includes (folder)header.phpfooter.phpstyle.cssmodel (folder)mysqli_connect.php.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
Intro to DatabasesClass 4 SQL REVIEW To talk to the database, you have to use SQL SQL is used by many databases, not just MySQL. SQL stands for Structured.
Creating PHPs to Insert, Update, and Delete Data CS 320.
PHP Form Introduction Getting User Information Text Input.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
PHP Database connectivity Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions.
DT228/3 Web Development Databases. Querying a database: Partial info Search engines, on-line catalogues often need to allow user to search a database.
Controlling Web Site Access Using Logins CS 320. Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP.
Module Review Basic SQL commands: Create Database, Create Table, Insert and Select 2. Connect an SQL Database to PHP 3. Execute SQL Commands in.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
>> PHP: Insert Query & Form Processing. Insert Query Step 1: Define Form Variables Step 2: Make DB Connection Step 3: Error Handling Step 4: Define the.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
PHP and SQL Server: Connection IST2101. Typical web application interaction (php, jsp…) database drivers 2IST210.
MySQL. Is a SQL (Structured Query Language) database server. Can be accessed using PHP with embedded SQL Queries Supports Large DB’s, 60,000 tables with.
U:/msu/course/cse/103 Day 21, Slide 1 CSE 103 Makeups –If you didn’t take one over the weekend, take one TUESDAY or WEDNESDAY!
PHP: MySQL. PHP Connect to MySQL PHP 5 and later can work with a MySQL database using: – MySQLi extension (the "i" stands for improved) – PDO (PHP Data.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
CSC 2720 Building Web Applications Accessing MySQL from PHP.
CSC 405: Web Application Engineering II8.1 Web programming using PHP What have we learnt? What have we learnt? Underlying technologies of database supported.
PHP Form Processing * referenced from
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
Dreamweaver - Forms questionnaire, register, login, etc.
PHP and SQL Server: Connection IST 210: Organization of Data IST2101.
PHP (Session 2) INFO 257 Supplement.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
Introduction to Web programming
PHP Overview PHP: Hypertext Preprocessor Server-Side Scripting
PHP and MySQL.
ISC440: Web Programming 2 Server-side Scripting PHP 3
Web Systems Development (CSC-215)
MySQL Web Application Connecting to a MySQL database
PHP: Combo box FdSc Module 109 Server side scripting and
MySQL Web Application Connecting to a MySQL database
Introduction to Web programming
PHP Programming Using Cloud 9 IDE.
Presentation transcript:

Web Database Programming Connecting Database to Web

Example Design Customers come to the web site and register. The sales department sets up a list of widgets that customers can order from. A customer makes one or more orders for widgets. When the order is filled the order is removed from the database. Widgets are classified by type.

SQL Query SELECT … FROM … WHERE … ORDER BY Examples of SQL –SELECT * FROM Customer –SELECT FirstName, LastName FROM Customer WHERE FirstName=“Andrew” AND LastName=“Fuller” –SELECT FirstName AS FName, LastName AS LName FROM Customer WHERE LastName=“Fuller” OR (YearOfBirth<"1950” AND Photograph Is Null) ORDER BY LastName

Get a Table and Display it on the Web Connect to a database server (get a handle to a connection) –Host –User name –Password Select a database Issue SQL query to get a table Fetch results row by row –Display each row Error checking in every step

Example Code Customer List <?php $db = mysql_connect(“db_host”, “db_user”,“db_pwd”) or die(“cannot connect”); mysql_select_db(“dbname”,$db) or die(“cannot select db”); $sql = “SELECT FirstName, LastName ”; $sql = $sql.“FROM Customer”; $result = mysql_query($sql,$db) or die(“query failed: ”.mysql_error()); while ($row = mysql_fetch_row($result)) { $fn = $row[“FirstName”]; $ln = $row[“LastName”]; print “ $fn $ln ”; } ?>

Include file Put database login information into a separate file –For Portability and security <?php $db_host = “localhost”; $db_user = “instruct”; $db_pwd = “xxxxx”; ?> Each database accessing script “include” this file at the beginning (or “require”) include(“db_login.php”); Use variables and functions in included file as if it is in this file

Using HTML Forms for Queries Example –For a customer table (FirstName, LastName) –Use a page to query the database, find a record, and display it –Later we will look at other actions you can take (insert, update, and delete) Notice –What happens when the user submits the form –Form display and form processing may be done with different files

The Form Display Part Tags in CustomerSimpleQueryForm.html Enter a first name: </form Notes –The form action is the URL of the file or script that will “handle” the form –The name of the form input field is used in the action file to identify the corresponding value, I.e. it is the same name in $_POST[‘name’]

The Action Query: $sql="SELECT FirstName, LastName from Customer "; $sql = $sql."WHERE FirstName='$_POST[queryFirstName]'"; $results = mysql_query($sql,$db) or die(“query failed: ”.mysql_error()); Notes –in SQL, enclose text in single quotes (‘text’) while numbers do not have them (e.g. 3 ) –The $sql string can be used for debugging (e.g. print(“sql = $sql”); )

The Output PhP Code Fragment while ($row = mysql_fetch_row($results)) { // print fields one by one // or use a loop print(" $row[0] $row[1] "); } Or: $count = mysql_num_rows($results); for ($i = 0; $i < $count; $i++) {… Note –what happens when result set is empty?

Redirect using header() The PHP function header() takes over the sending of the “header” to the client Example: if (!$_POST[queryFirstName]) { // there was no id value // so send the user to the add form header(“Location: add.html”); exit; // and get out of here! } Note there can be NO OUTPUT prior to the use of header() – no print statements – not even a blank line (outside of the <?php tag)

Alternate means of doing a Query URL parameters –On the URL following ?, and separated by & –Each value is a name=value pair –For example: yes These parameters can be accessed with $_GET[‘name’]