Session 7: Getting PHP to Talk to MySQL. Objectives Connecting to the Database Building & Executing the SQL SELECT Query Fetching & Displaying the data.

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

PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect.
Widhy Hayuhardhika NP, S.Kom. Overview of database structure Connecting to MySQL database Selecting the database to use Using the require_once statement.
MySQL Access Privilege System
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic PHP.
PHP and MySQL. Why Use a Database  Easy access to data  Simultaneous access by multiple users is handled properly  Security - easy to control access.
PHP and MySQL PHP for the Web, page PHP and MySQL MySQL Resource PHP – MySQL Resource
Manipulating MySQL Databases with PHP. PHP and mySQL2 Objectives Connect to MySQL from PHP Learn how to handle MySQL errors Execute SQL statements with.
Objectives Connect to MySQL from PHP
MySQL and PHP By Trevor Adams.
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 Programming. Topics Background and History of PHP Installation Comments in PHP Variables Conditions Loops Functions File Handling Database Handling.
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
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 &
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
Chapter 7 PHP Interacts with Ms. Access (Open DataBase Connectivity (ODBC))
Sayed Ahmed Computer Engineering, BUET, Bangladesh MSC, Computer Science, U of Manitoba, Canada
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
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)
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 19: Database Support.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Python MySQL Database Access
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
Website Development & Management Getting Started with Databases Instructor: John Seydel, Ph.D. CIT Fall
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
Comp 519: Web Programming Autumn 2014 Advanced SQL and PHP Advanced queries Querying more than one table Searching tables to find information Aliasing.
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.
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.
Lecture 10 – MYSQL and PHP (Part 2)
Accessing Your MySQL Database from the Web with PHP (Ch 11) 1.
PHP with MySQL 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.
 PEAR supplies a number of open source extensions to PHP including its DB package, which provides a database abstraction layer  so that the PHP programmer.
Web-Based Database Programming with PHP. Dept. of Computing Science, University of Aberdeen2 In this lecture you will learn PHP Basics PHP functions –To.
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
Retrieving data from MySQL using PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
2010/11 : [1]PHP with MySQLBuilding Web Applications using MySQL and PHP (W1) PHP with MySQL.
13. PHP: Insert, View Data. M. Udin Harun Al Rasyid, S.Kom, Ph.D Desain dan Pemrograman.
PHP Database connectivity Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions.
PHP Database Processing CIS 1715 Web Technologies.
Li Tak Sing COMPS311F. Database programming JDBC (Java Database Connectivity) Java version of ODBC (Open Database Connectivity) ODBC provides a standard.
PHP Programming. Topics Database Handling (MySQL, MSSQL, ODBC)
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
CSC 2720 Building Web Applications Accessing MySQL from PHP.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
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.
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
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.
Web Database Programming Using PHP
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Web Database Programming Using PHP
Server-Side Application and Data Management IT IS 3105 (FALL 2009)
ISC440: Web Programming 2 Server-side Scripting PHP 3
Chapter 8 Working with Databases and MySQL
Erasmus Exchange in Ionian University
Presentation transcript:

Session 7: Getting PHP to Talk to MySQL

Objectives Connecting to the Database Building & Executing the SQL SELECT Query Fetching & Displaying the data Using PEAR

The Process Connect to the database Select the database to use Build a SELECT statement Perform the query Display the result

Including Database Login Details

Connecting to the Database

Selecting the Database All mysql related functions have an optional parameter – the database connection. If you don’t specify the connection, the connection is the latest result of calling mysql_connect

Building the SQL SELECT Query Use a variable named $query to store the SQL Statement Build up a query in parts using the string concatenation (.) operator

Executing the Query Using the mysql_query() function The results form a result set. Each element corresponds to a row. To display them, process each row, one at a time

Fetching and Displaying Use mysql_fetch_row() function to get the rows from the result set The function returns one row at a time until there are no more rows. If there are no more rows, it return FALSE. Thus, use a loop to fetch and display the result set.

Fetching and Displaying (cont.) Use mysql_fetch_array() function First parameter: the result set Second parameter (optional) MYSQL_ASSOC, array is indexed based on columns’s names MYSQL_NUM, array is index based on number starting at zero MYSQL_BOTH, both types above

Fetching and Displaying (cont.) Use mysql_fetch_assoc() function

Closing Connection Close the connection when finishing Closing the connection will free any resources and memory allocated to it by MySQL and PHP Syntax: mysql_close($connection)

Using PEAR PEAR is a framework and distribution system for reusable PHP components There are many modules which is categorized

Installing PEAR Go to the command line window Go to the path C:\php Type go-pear.bat At the first question, type local Confirm by typing yes

Installing PEAR (cont.) At the next question, type all

Installing PEAR (cont.) Answer 12 question as following

Installing PEAR (cont.) Then Enter At the altering php.ini question, type Y Then Enter And finish installing of PEAR

Adding Additional Package Access PEAR Package Manager by entering pear at the command prompt Adding new modules: pear install package_name

Using PEAR DB Include the PEAR DB package Create a connection Connect string Dbtype: dbase, msql, mssql, mysql, mysqli, oci8, odbc, pgsql, … Querying Fetching

Using PEAR DB (cont.) Closing PEAR error reporting

Practice Develop an Image Collection System with following functions User Module  Register a new user  Change password  Edit user profile  Logon/logout Album Module  Create a new, empty album  Upload images to the album  Delete images of an album  Sort images based on size, name, date of upload  View album Task: Design the database structure Create the database with MySQL