PHP - MySQL Connection 8 March 2006 Adina Crainiceanu www.cs.usna.edu/~adina IT420: Database Management and Organization.

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.
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 –Writing Reusable Code 10 March 2006 Adina Crainiceanu IT420: Database Management and Organization.
PHP and MySQL. Why Use a Database  Easy access to data  Simultaneous access by multiple users is handled properly  Security - easy to control access.
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
Multiple Tiers in Action
MySQL and PHP By Trevor Adams.
PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
SJSU CS157B Dr. Lee1  2004 Jenny Mitchell Two Useful Tools You Can’t Live Without by Jenny Mitchell SJSU CS157B Section PHP and MySQL.
PHP : Working with Resultsets. Last class  Open a connection to the MySQL server.  Specify the database  Issue queries (no updates at this stage) 
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.
PHP1-1 PHP & SQL Xingquan (Hill) Zhu
© 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.
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.
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)
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
MySQL and PHP 3 March 2006 Adina Crainiceanu IT420: Database Management and Organization.
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.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Lec_6 Manipulating MySQL Databases with PHP PHP Programming with MySQL.
MySQL PHP Web Technology. Logging in to Command Line Start -> Programs -> AppServ -> MySQL Command Line Client Enter Password, then you’ll be working.
MySQL Databases & PHP Integration Using PHP to write data to, and retrieve data from, a MySQL database.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Intro to LAMP Programming Presented for CIS Faculty at SAC by Dan Zollars.
Lecture 10 – MYSQL and PHP (Part 2)
Technology & Management Club Development Software Overview.
Accessing Your MySQL Database from the Web with PHP (Ch 11) 1.
Database Access with PHP and MySQL CS356 Examples from Web Database Applications, by Hugh E. Williams & David Lane, O'Reilly, 2002.
PHP+MySQL Integration. Connecting to databases One of the most common tasks when working with dynamic webpages is connecting to a database which holds.
1 IT420: Database Management and Organization Database Security 5 April 2006 Adina Crăiniceanu
MySQL Database Connection
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 LAMP Programming Presented for SAT Linux Users' Group by Dan Zollars.
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.
THE WEBMASTERS: SENG + WAVERING.  On account of construction, we will be having class in room 1248 next week.
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.
CS453: Databases and State in Web Applications (Part 2) Prof. Tom Horton.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
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)
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.
Accessing mySQL relational database. MySQL database.  Today, we will attempt and open a connection to the MySQL server.  We need to specify the database.
Database MySQL Universitas Muhammadiyah Surakarta Yogiek Indra Kurniawan.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
>> PHP: MySQL & CRUD. R ecall Database Tables Records is composed of Operations (CRUD) Create Retrieve Update Delete DBMS Access Control MySQL phpMyAdmin.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
How Web Database Architectures Work CPS181s April 8, 2003.
PHP MySQL1 PHP and MySQL After this lecture, you should be able to:  Access a MySQL database with PHP  mysql_connect()  mysql_select_db()  mysql_query()
OBJECTIVES Learn how to view data using SQL and PHP Learn how to add new data using SQL and PHP PHP+SQL: View and Adding,
Server-Side Application and Data Management IT IS 3105 (FALL 2009)
PHP and MySQL.
Accessing Your MySQL Database from the Web with PHP (Ch 11)
PHP: Database Basic Selection FdSc Module 109
Web Programming– UFCFB Lecture
PHP AND MYSQL.
Database Access with PHP and MySQL
Presentation transcript:

PHP - MySQL Connection 8 March 2006 Adina Crainiceanu IT420: Database Management and Organization

Web Database Architecture Client browser Web server with PHP enabled Database Management System HTTPAPI

Goals Today  Connect from PHP to MySQL

MySQL  Relational Database Management System  Free  Open source  Portable  High performance  Support available

Example Application Database: dbmusic Table: songs(ISBN, Title, SingerID, Length)

Use DBMS from PHP  Connect to the database server  Specify database to use  Send queries and retrieve results  Process results  Close connection  All PHP functions return ‘false‘ if operation unsuccessful!

Example: $searchterm = $_POST['searchterm']; $db = mysql_connect('localhost','root'); if (!$db){ echo('connect failed'); exit; } $dbselected= mysql_select_db('dbmusic') or exit('could not select db'); //query $query = "select * from songs where Title like '%$searchterm%'"; //process results $results = mysql_query($query) or die("could not retrieve rows"); while ($row = mysql_fetch_row($results)){ echo 'Title: '.$row[1].' '; } //close connection mysql_free_result($results); mysql_close($db);

Connect to MySQL  dbconnection mysql_connect(servername, username, [password])  Always test and handle errors!  Example: $dbconn = mysql_connect(‘localhost’,’root’); if (!$dbconn){ echo ‘Could not connect to db. Exit’; exit; }

Select Database to Use  bool mysql_db_select(dbname, [dbconnection])  Always test and handle errors!  Example: $dbs = mysql_db_select(‘dbmusic’) or die(‘Could not select db’);

Query the Database  qresult mysql_query(query)  Example: $query = “select * from songs where Title like ‘%home%’ ”; $results = mysql_query($query);

Process Select Results  nbrows = mysql_num_rows(qresult)  row = mysql_fetch_row(qresult)  row = mysql_fetch_array(qresult)  Example: while ($row = mysql_fetch_row($results)){ foreach($row as $column) echo “$column ”; echo “ ”; }

Check Modification Results  intvar = mysql_affected_rows()  Used after INSERT, DELETE, UPDATE

Disconnect from Database  Free query results  mysql_free_result(qresult);  Close connection  mysql_close(connection)

VP-5 MVR Fund Raiser Application

Lab Exercise  Recover the database vp5fund created last time  D:\sokkit\mysql\data  Start MySQL Monitor  D:  cd sokkit\mysql\bin  mysql –u root  To use the database: use vp5fund;  These tables should exist:  Items(ItemName, Price)  Orders(OrderID, ShippingAddress)  ItemsOrdered(OrderID, ItemName, Quantity)  Insert few rows in tables

Lab Exercise: PHP + MySQL  Display all orders from VP-5 Fund Raiser application. For each order display:  OrderID  Shipping address  Items names and price  Display all orders from VP-5 Fund Raiser application with shipping address in Maryland.

Lab Exercise: PHP + MySQL  Save order data from VP-5 Fund Raiser application into vp5fund database.

Save Your Work!  Copy the D:\sokkit\mysql\data\ directory to your X drive