PHP Database Processing CIS 1715 Web Technologies.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Widhy Hayuhardhika NP, S.Kom. Overview of database structure Connecting to MySQL database Selecting the database to use Using the require_once statement.
Keys, Referential Integrity and PHP One to Many on the Web.
E-Invoice System CS541 Database Systems Class Project By: Parul Gupta.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved.
Faculty of Sciences and Social Sciences HOPE PHP & MySQL Stewart Blakeway FML 213
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic PHP.
PHP and MySQL PHP for the Web, page PHP and MySQL MySQL Resource PHP – MySQL Resource
Objectives Connect to MySQL from PHP
MySQL and PHP By Trevor Adams.
Website Development & Management PHP Odds & Ends Instructor: John Seydel, Ph.D. CIT Fall
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.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
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,
7/8/05MySQL David Lawrence1 David Lawrence, JLab An introduction for the novice.
1 Chapter 8 – Working with Databases spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
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:
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
PHP MySQL Introduction
INTERNET APPLICATION DEVELOPMENT PRACTICAL ON CONNECTING TO MYSQL.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
 Mysql – popular open-source database management system  PHP usually works with Mysql for web- based database applications  LAMP applications—Web-based.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
Website Development & Management Getting Started with Databases Instructor: John Seydel, Ph.D. CIT Fall
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.
PHP MySQL. SQL: Tables CREATE TABLE tablename { fieldname type(length) extra info,... } Extra info: –NULL (allows nulls in this field) –Not NULL (null.
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.
Lec_6 Manipulating MySQL Databases with PHP PHP Programming with MySQL.
Chapter 6 PHP Interacts with Mysql Database. Introduction In PHP, there is no consolidated interface. Instead, a set of library functions are provided.
Polling System Part 1 Creating PHP & MySQL Files CIS 254.
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.
Lecture 10 – MYSQL and PHP (Part 2)
MySQL Database Connection
Session 7: Getting PHP to Talk to MySQL. Objectives Connecting to the Database Building & Executing the SQL SELECT Query Fetching & Displaying the data.
CHAPTER 9 PHP AND MYSQL. A POSSIBLE SITE CONFIGURATION Application Folder index.php includes (folder)header.phpfooter.phpstyle.cssmodel (folder)mysqli_connect.php.
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
Creating PHPs to Insert, Update, and Delete Data CS 320.
Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
Login to a Database (from a Webpage), Inserting data into a database from a form, getting data from database and display on Webpage Done by: Mashail Alsolamy.
2010/11 : [1]PHP with MySQLBuilding Web Applications using MySQL and PHP (W1) PHP with MySQL.
PHP Database connectivity Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions.
PHP and Mysql Database. PHP and Database Mysql – popular open-source database management system PHP usually works with Mysql for web-based database applications.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
PHP and SQL Server: Connection IST2101. Typical web application interaction (php, jsp…) database drivers 2IST210.
Accessing mySQL relational database. MySQL database.  Today, we will attempt and open a connection to the MySQL server.  We need to specify the database.
 Connectivity Function :-  mysql_connect ()  mysql_select_db ()  mysql_query ()  mysql_nam_rows ()  mysql_fetch_row ()  mysql_affected_rows () 
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
Setting up a Development Environment. What you need Webserver (Apache) Database (MySQL) PHP All in Uniserver (google “uniserver”) Download the windows.
Module of the week Webform 7.x-4.0-alpha9 – admin/config/content/webform Add content types, choose allowed fields, default values and advanced options.
PHP and SQL Server: Connection IST 210: Organization of Data IST2101.
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.
Tried my best to simplify it for you!
Session 4 PHP & MySQL.
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 ©
Erasmus Exchange in Ionian University
PHP: Database Basic Selection FdSc Module 109
PHP: Database connection
Web Programming– UFCFB Lecture
PHP AND MYSQL.
Presentation transcript:

PHP Database Processing CIS 1715 Web Technologies

PHP Database Processing In this exercise, we will learn how to create a dynamic XTML Select list from data stored in our states table.

Select List Markup Alabama Alaska Arkansas. Washington We can create the select list dynamically with PHP by querying the states table Each option element is echoed out in a while loop

PHP Database Processing In this unit we will cover the PHP elements required to process MySQL databases – Database Concepts – Connecting to the database mysql_connect() – Selecting the database to use mysql_select_db() – Perform required database processing Create Read Update Delete – Closing the database connection mysql_close()

States Table Fields

PHP Database Processing Example $db_connection = mysql_connect (“localhost”, “webdev”, “webdevpass”) or die ( mysql_error() ) ; – This statement establishes a connection to the database using the constant values – If the connection fails, we stop processing with the die() function

PHP Database Processing Example $db_select = mysql_select_db(“cis1715”) or die ( mysql_error() ); – This statement selects which database will be use in subsequent SQL queries – If the function fails we stop processing using the die() function

PHP Database Processing Once the connection has been established and the database has been selected, we can begin executing SQL statements The SQL SELECT statement is used to read data from the states table in the database

mysql_query() Function Syntax – mysql_query(‘sql_statement’) – Where sql_statement is an valid SQL statement Example $query_result = mysql_query (“SELECT * FROM states“) or die (mysql_error()); $query_result is a reference to the returned record set

PHP Database Processing Once the query is executed, we need to loop through the returned record set This is done using a while loop in combination with the mysql_fetch_assoc() function The mysql_fetch_assoc() function accepts one argument and returns the fields of the fetched rows as an associative array

PHP Database Processing Syntax – mysql_fetch_assoc(recordset_ref) Where recordset_ref is the reference to the returned recordset (from previous SQL statement)

PHP Database Processing Example $row = mysql_fetch_assoc($query_result) – In this example fields are fetched from the query result and placed in the $row table – The individual fields in the fetched row are referenced using the following syntax $row[‘fieldname’]

PHP Database Processing The mysql_fetch_assoc() function is used with a while loop to loop through all the rows of the returned recordset The mysql_fetch_assoc() returns true as long as there are rows in the recordset

PHP Database Processing Example while ($row = mysql_fetch_assoc($query_result)) { echo $row[‘lname’]; } In this example, we loop through the returned recordset and display the lname field of each row The lname field is a field in the table queried

PHP Database Processing After we have looped through the returned recordset we release resources and close the connection as follows – mysql_free_result($query_result); – mysql_close();

PHP Database Processing The following example illustrates PHP database processing used in the context of an HTML document for format a table

<?php // connect to database $db_connection = mysql_connect (“localhost”, “webdev”, “webdevpass”) or die ( mysql_error() ) ; // select database to use $db_select = mysql_select_db(“cis1715”) or die ( mysql_error() ); // Execute query. Select all customer rows $query_result = mysql_query (“SELECT * FROM states”) or die ( mysql_error() ); ?>

<?php while ($row = mysql_fetch_assoc($query_result)) { ?> ”> <?php } // end while loop mysql_free_result($query_result); mysql_close(); ?>