1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.

Slides:



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

Widhy Hayuhardhika NP, S.Kom. Overview of database structure Connecting to MySQL database Selecting the database to use Using the require_once statement.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Objectives Connect to MySQL from PHP
Intermediate PHP & MySQL
PHP and MySQL Web Development tMyn1 PHP and MySQL Web Development When you install PHP, you can select from a number of extensions. The MySQL support in.
Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql.
PHP Scripts HTML Forms Two-tier Software Architecture PHP Tools.
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.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
INTERNET APPLICATION DEVELOPMENT For More visit:
© 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.
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:
Server-side Scripting Powering the webs favourite services.
PHP – MySQL Extensions. Table used in most examples CREATE TABLE product ( rowID INT NOT NULL AUTO_INCREMENT, productid VARCHAR(8) NOT NULL, name VARCHAR(25)
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
PHP meets MySQL.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
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.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
Chapter 6 PHP Interacts with Mysql Database. Introduction In PHP, there is no consolidated interface. Instead, a set of library functions are provided.
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.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
Accessing Your MySQL Database from the Web with PHP (Ch 11) 1.
PHP+MySQL Integration. Connecting to databases One of the most common tasks when working with dynamic webpages is connecting to a database which holds.
Web-Based Database Programming with PHP. Dept. of Computing Science, University of Aberdeen2 In this lecture you will learn PHP Basics PHP functions –To.
Prof Frankl, Spring 2008CS Polytechnic University 1 Overview of Web database applications with PHP.
Session 7: Getting PHP to Talk to MySQL. Objectives Connecting to the Database Building & Executing the SQL SELECT Query Fetching & Displaying the data.
CHAPTER 7 Form & PHP. Introduction All of the following examples in this section will require two web pages. The first page retrieves information posted.
Creating PHPs to Insert, Update, and Delete Data CS 320.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
2010/11 : [1]PHP with MySQLBuilding Web Applications using MySQL and PHP (W1) PHP with MySQL.
Topics Sending an Multipart message Storing images Getting confirmation Session tracking using PHP Graphics Input Validators Cookies.
PHP Database Processing CIS 1715 Web Technologies.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
Since you’ll need a place for the user to enter a search query. Every form must have these basic components: – The submission type defined with the method.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,
1 PHP and MySQL Web Development When you install PHP, you can select from a number of extensions. The MySQL support in PHP consists of a number of functions.
2440: 141 Web Site Administration Web Forms Instructor: Joseph Nattey.
Web Database Programming Using PHP
Introduction to Dynamic Web Programming
Web Database Programming Using PHP
PHP Functions Besides the built-in PHP functions, we can create our own functions. A function is a block of statements that can be used repeatedly in.
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 ©
Web DB Programming: PHP
PHP and Forms.
PHP: Database connection
PHP-II.
Presentation transcript:

1 PHP and MySQL

2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL

3 Querying Data with PHP  Opening and Using a Database  Error Handling of MySQL Database Functions  Formatting Results  Using Include Files PHP and MySQL

4 Opening and Using a Database  In PHP, there is no consolidated interface.  A set of library functions are provided for executing SQL statements, as well as for managing result sets returned from queries, error handling, and setting efficiency options.  Connecting to and querying a MySQL DBMS with PHP is a five-step process: 1.Connect to the DBMS and use a database. »Open a connection to the MySQL DBMS using mysql_connect( ). PHP and MySQL

5 Opening and Using a Database »There are three parameters:  The hostname of the DBMS server to use  A username  A password »Once you connect, you can select a database to use through the connection with the mysql_select_db( ) function. »The function mysql_connect( ) returns a connection handle. »A handle is a value that can be used to access the information associated with the connection. PHP and MySQL

6 Opening and Using a Database 2.Run the query using mysql_query( ). »The function takes two parameters:  The SQL query itself  The DBMS connection to use  The connection parameter is the value returned from the connection in the first step. »The function mysql_query( ) returns a result set handle resource; that is, a value that can retrieve the output—the result set—of the query in Step 3. PHP and MySQL

7 Opening and Using a Database 3.Retrieve a row of results. »The function mysql_fetch_row( ) retrieves one row of the result set. »The function takes only one parameter:  The result set handle from the second step »Each row is stored in an array $row, and the attribute values in the array are extracted in Step 4. »A while loop is used to retrieve rows until there are no more rows to fetch. »The function mysql_fetch_row( ) returns false when no more data is available. PHP and MySQL

8 Opening and Using a Database 4.Process the attribute values. »For each retrieved row, a for loop is used to print with an echo statement each of the attributes in the current row. »Use mysql_num_fields( ) is used to return the number of attributes in the row; that is, the number of elements in the array. »The function takes only one parameter:  The result set handle from the second step »The data itself is stored as elements of the array $row returned in Step 3. PHP and MySQL

9 Opening and Using a Database 5.Close the DBMS connection using mysql_close( ) » The function takes only one parameter:  The connection to be closed. Example 4-1 Example 4-2 Example 4-3 Example 4-4 PHP and MySQL

10 Error Handling of MySQL Database Functions  Database functions can fail.  There are several possible classes of failure, ranging from critical—the DBMS is inaccessible or a fixed parameter is incorrect to recoverable, such as a password being entered incorrectly by the user. Example 4-5 PHP and MySQL

11 Formatting Results  Basic techniques for connecting to and querying a MySQL DBMS using PHP can be extended to produce results with embedded HTML that have both better structure and presentation. Example 4-6 PHP and MySQL

12 Using Include Files  Include directives allow common functions in other files to be accessible from within the body of a script without directly adding the functions to the code. Example 4-7 Example 4-8 PHP and MySQL

13 User-Driven Querying  User Input  Passing Data with URLs  Passing Data with the HTML Environment  Passing Data with Embedded Links  How PHP Initializes Variables  Querying with User Input  Combined Scripts PHP and MySQL

14 User Input  Three techniques can be used to pass data that drives the querying process in a web database application:  Manual entry of a URL to retrieve a PHP script resource and provide parameters to the resource. »For example, a user may open a URL using the Open Page option in the File menu of the Netscape web browser.  Data entry through HTML environments. »For example, environments can capture textual input, and input is made by selecting radio buttons, selecting one or more items from a drop-down select list, clicking on buttons, and through other data entry widgets. PHP and MySQL

15 User Input  Embedded hypertext links that can be clicked to retrieve a PHP script resource and provide parameters to the script. PHP and MySQL

16 Passing Data with URLs  Before the script is processed by the PHP scripting engine, variables associated with any parameters to the resource are initialized and assigned values. Example 5-1 PHP and MySQL

17 Passing Data with the HTML Environment  The second technique that captures data passed from a browser to a server is the HTML environment. Example 5-2 PHP and MySQL

18 Passing Data with Embedded Links  The third technique that passes data from a web browser to a web server is embedding links in an HTML document.  This technique runs queries in most web database applications and is conceptually similar to manually entering a URL. Example 5-3 PHP and MySQL

19 How PHP Initializes Variables  When the PHP script engine is invoked, the engine declares and initializes variables in a predefined order.  The automatic initialization feature works in this order: 1.By default, environment variables are initialized first. 2.Variables are initialized from query string parameters passed with the GET method. 3.POST method parameters are initialized. 4.Variables from cookies are initialized. PHP and MySQL

20 How PHP Initializes Variables 5.The Apache server internal variables are initialized.  The initialization order can be changed from the default by adjusting the variables_order setting in php.ini. PHP and MySQL

21 Querying with User Input  To introduce querying with user input, we begin by explaining a script that retrieves the wines made in a wine region that is specified by a user. Example 5-5.Example 5-5 PHP and MySQL

22 Combined Scripts  Some approaches separates the HTML and the PHP processing script into two files.  It is more common to implement both in the same script where the code can produce a or run a query, depending if user parameters are supplied.  If the script is called with no parameters, the script produces a for user input and, if it is called with input from the, it runs the query. This is called a combined script. Example 5-6Example 5-6. PHP and MySQL

23 Writing Data with PHP and MySQL  Database Inserts, Updates, and Deletes  Uploading and Inserting Files into Databases  Updating data  Deleting data PHP and MySQL

24 Database Inserts, Updates, and Deletes  Simple database insertions and updates are much the same as queries.  Inserting, updating, and deleting data does require some additional care. Example 6-1 PHP and MySQL

25 Inserting data  Phase one of the insertion process is data entry. Example 6-5  The second phase of insertion is data validation and then the database operation itself. Example 6-6 PHP and MySQL

26 Updating data  Updating data is usually a more complex process than inserting it. A three-step process for updates is used in most web database applications:  Using a key value, matching data is read from the database.  The data is presented to the user for modification.  The data is updated by writing the modified data to the database, using the key value from the first step. Example 6-7 Example 6-8 PHP and MySQL

27 Deleting data  The basic principle of deletion is a two-step process:  Identify the row or rows to be deleted  Remove the data with an SQL DELETE statement.  As in an update, the first step requires a key value be provided, and any technique described for capturing keys in updates can be used.  We assume here that a unique, primary key value for the row to be deleted is available. Example PHP and MySQL