SYST 28043 Web Technologies SYST 28043 Web Technologies Databases & MySQL.

Slides:



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

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.
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.
Objectives Connect to MySQL from PHP
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
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.
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,
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
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.
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:
Create an online booking system (login/registration)
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))
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
INTERNET APPLICATION DEVELOPMENT PRACTICAL ON CONNECTING TO MYSQL.
MySQL + PHP.  Introduction Before you actually start building your database scripts, you must have a database to place information into and read it from.
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.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Python MySQL Database Access
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
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.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
PHP Part 2.
1. Connecting database from PHP 2. Sending query 3. Fetching data 4. Persistent connections 5. Best practices.
Lecture 10 – MYSQL and PHP (Part 2)
Intro to DatabasesClass 4 SQL REVIEW To talk to the database, you have to use SQL SQL is used by many databases, not just MySQL. SQL stands for Structured.
Creating PHPs to Insert, Update, and Delete Data CS 320.
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.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
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.
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.
SYST Web Technologies SYST Web Technologies XHTML Forms.
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.
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.
>> 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.
MySQL MySQL and PHP – interacting with a database.
Labtest.ASP Notes. INSERT STATUS INSERT STATUS
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
Programming for the Web MySQL Command Line Using PHP with MySQL Dónal Mulligan BSc MA
Software-Projekt 2008 Seminarvortrag“Short tutorial of MySql“ Wei Chen Verena Honsel.
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Introduction to Web programming
Web Design and Development
Introduction to Web programming
ISC440: Web Programming 2 Server-side Scripting PHP 3
Chapter 8 Working with Databases and MySQL
Introduction to Web programming
Presentation transcript:

SYST Web Technologies SYST Web Technologies Databases & MySQL

10/15/2015Wendi Jollymore, ACES2 Database Overview Database: A collection of related Tables A database server could house many databases Table: A collection of records that describe items in an entity Some sytems call this a “file” E.g. Employee Table contains Employee Records

10/15/2015Wendi Jollymore, ACES3 Database Overview Record: Describes a single item Collection of Fields or Columns Also called a Row Field: A single data element Also called a column Describes a piece of an item

10/15/2015Wendi Jollymore, ACES4 Database Overview

10/15/2015Wendi Jollymore, ACES5 Database Overview

10/15/2015Wendi Jollymore, ACES6 Database Overview Primary Key A special field that acts as a unique identifier for a record Must be unique for each record Each table must have one Examples: Student ID, Social Insurance #, Product ID

10/15/2015Wendi Jollymore, ACES7 Database Overview - Exercises 1. Besides Students, what other tables do you think would exist in a database for Sheridan College? 2. Define a structure for a table called Mp3s that you would use to keep track of all your MP3 files. 3. Make up three examples of records with field values for the Mp3s table in #2.

10/15/2015Wendi Jollymore, ACES8 Using MySQL In order to create database-driven pages, you need a database server We will use MySQL You will need to go in and create databases and tables that your pages can use We’ll use the PHPMyAdmin tool!

10/15/2015Wendi Jollymore, ACES9 Using MySQL Go to Log in using the user name and password you set up when you installed XAMPP In the left-hand menu, select phpMyAdmin Log in using the root password you set up for your Sql server when you installed XAMPP

10/15/2015Wendi Jollymore, ACES10 Using MySQL Click on the Databases tab and find “Create Database” Name: Media Collation: latin1_general_ci (optional) Click Create Create the Table: Name: Cds Number of fields: 4 Click Go

10/15/2015Wendi Jollymore, ACES11 Using MySQL Fill in the information for all four fields See notes online for field details Add a description Click Save

10/15/2015Wendi Jollymore, ACES12 Using MySQL We can’t use the root account for web pages Too powerful for a regular site visitor Add a Guest user: On main admin page, Users tab Click Add new user Fill in the user name and password Select Host: Local For Global Privileges, check SELECT, INSERT, UPDATE, DELETE Click Add User button bottom-right

10/15/2015Wendi Jollymore, ACES13 Accessing the DB Create the form in the notes Use this to get user data to store PHP file will be used to retrieve the data and save it to the database table Open a new PHP file Add variables for user name, host, password Use the guest name and password you created

10/15/2015Wendi Jollymore, ACES14 Accessing the DB To perform any task with your table data: Connect to the database server Select the database you want to work with Perform the commands you want

10/15/2015Wendi Jollymore, ACES15 Accessing the DB Connecting to the server: mysql_connect(host, user, passwd) Connects to a database server with a specific user name and password Returns a reference to the database connection object $dblink = mysql_connect($hostname, $user, $passwd) or die ("Error: No connection to MySQL server\n");

10/15/2015Wendi Jollymore, ACES16 Accessing the DB Selecting the database: mysql_select_db(db, conn) Selects a specific database using a connection that has already been created mysql_select_db($dbname, $dblink) or die ("Error: MySQL database not selected\n");

10/15/2015Wendi Jollymore, ACES17 Accessing the DB Executing an SQL statement: mysql_query(cmd, conn) Executes a specific command or query using a database connection If cmd is a SELECT statement, function returns a set of records If cmd is INSERT, DELETE, UPDATE, $result true if successful, false if not $result = mysql_query($sql, $dblink) or die ("SQL query failed: $sql ".mysql_error());

10/15/2015Wendi Jollymore, ACES18 Accessing the DB In your PHP file: At the top, add variables for host, user, password Normally these are stored somewhere else In the tag: Connect to the database Select the Media table

10/15/2015Wendi Jollymore, ACES19 Retrieving Form Data You sent your form data using method=“post” To access in PHP file: $_POST[“fieldname”] Fieldname is the value in the input element’s name=“” attribute isset($_POST[“fieldname”]) function Returns true if the field has a value $cdTitle = (isset($_POST["title"])) ? $_POST["title"] : "";

10/15/2015Wendi Jollymore, ACES20 Inserting Records The SQL INSERT statement allows you to add records: INSERT INTO tableName (f1, f2, f3,...) VALUES (v1, v2, v3…); Inserts the values v1 into field f1, the value v2 into field f2, etc… You can build an SQL statement using the form data

10/15/2015Wendi Jollymore, ACES21 Inserting Records Add the code to build the SQL INSERT query Execute the query If the result returned is greater than 0, display a confirmation message If the result is 0 or less, display an error message Check the notes!

10/15/2015Wendi Jollymore, ACES22 Inserting Records Use phpMyAdmin to check your table and see if the record was added! Check the notes online for complete code solution

Displaying Records A SELECT query will select a specific set of records SELECT fields FROM table WHERE condition Fields = comma delimited list of fields If you want all fields, use * instead WHERE clause is optional SELECT id, lastName, firstName FROM Students SELECT * FROM Wine WHERE price > 50.0 SELECT * FROM Wine WHERE estate LIKE ‘%Jackson%’ 10/15/2015Wendi Jollymore, ACES23

Displaying Records Once you run a query, you’ll want to get the results Determine how many records are in the result set $rows = mysql_num_rows($result); Access a row in the result set $myRecord = mysql_fetch_array($result); Access fields in a fetched row echo “Name: “.$myRecord[“lastName”].”, “.$myRecord[“firstName”]; 10/15/2015Wendi Jollymore, ACES24

Displaying Records Try the demos in the notes: Display all records in a table Display only records between a user- specified min and max price Do the search exercise 10/15/2015Wendi Jollymore, ACES25