MySQL and PHP 3 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.
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 Scripts HTML Forms Two-tier Software Architecture PHP Tools.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
PHP Programming. Topics Background and History of PHP Installation Comments in PHP Variables Conditions Loops Functions File Handling Database Handling.
SJSU CS157B Dr. Lee1  2004 Jenny Mitchell Two Useful Tools You Can’t Live Without by Jenny Mitchell SJSU CS157B Section PHP and MySQL.
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,
CSCI 6962: Server-side Design and Programming
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Class 3 MySQL Robert Mudge Reference:
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.
Slide 8-1 CHAPTER 8 Using Databases with PHP Scripts: Using MySQL Database with PHP.
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 Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
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.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L12_JDBC_MySQL 1 MySQL and JDBC.
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
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.
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.
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.
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
PHP - MySQL Connection 8 March 2006 Adina Crainiceanu IT420: Database Management and Organization.
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:
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Inserting Data.
PHP Database connectivity Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions.
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.
PHP getting data from a MySQL database. Replacing XML as data source with MySQL Previously we obtained the data about the training session from an XML.
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.
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.
CSC 405: Web Application Engineering II8.1 Web programming using PHP What have we learnt? What have we learnt? Underlying technologies of database supported.
MySQL MySQL and PHP – interacting with a database.
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,
Software-Projekt 2008 Seminarvortrag“Short tutorial of MySql“ Wei Chen Verena Honsel.
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
Web Design and Development
Easy Way to Reset WordPress Admin Password on Localhost? Guided By: WPGLOBALSUPPORTWPGLOBALSUPPORT.
PHP and MySQL.
PHP: Database Basic Selection FdSc Module 109
PHP: Database connection
Web Programming– UFCFB Lecture
Presentation transcript:

MySQL and PHP 3 March 2006 Adina Crainiceanu IT420: Database Management and Organization

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

Why Use DBMS?  Fast access to data  Queries to easily extract data  Built-in concurrency control  Built-in security control

Learned So Far… Client browser Web server with PHP enabled Database Management System HTTPAPI

Goals Today  MySQL  Connect from PHP to MySQL

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

Working with MySQL  SQL Monitor  Always available  Write SQL statements  ; after each statement!  PHPMyAdmin

Current Settings  Each machine is a server – web, db  Web server: localhost:80  MySQL server: localhost:3306  MySQL user: root, no password  ALL privileges  Disk location D:/sokkit  site/  mysql/

Lab Demo  Start MySQL server  Use MySQL – local machine

Lab Exercise  Start MySQL server  Sokkit Control Panel  Start database  Start MySQL monitor  D:/sokkit/mysql/bin/mysql –u root  Create a database called vp5fund  create database vp5fund;  Check database was created  show databases;

SQL for MySQL  Surrogate keys variant:  AUTO_INCREMENT  If column value left blank, generated value = max+1  show  databases  tables  describe tableName

VP-5 MVR Fund Raiser Application

Lab Exercise  To use the database just created:  use vp5fund;  Create table (use SQL)  Items(ItemName, Price)  Orders(OrderID, ShippingAddress)  ItemsOrdered(OrderID, ItemName, Quantity)  Insert few rows in tables  List all rows in Orders table (use SQL)

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 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 “ ”; }

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

Lab Exercise  Save order data from VP-5 Fund Raiser application into vp5fund database. Display appropriate message in order confirmation screen.  Display all orders from VP-5 Fund Raiser application.  Display all orders from VP-5 Fund Raiser application with shipping address in Maryland.

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