Class 3 MySQL Robert Mudge Reference:

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.
NMD202 Web Scripting Week5. What we will cover today PHPmyAdmin Debugging – using print_r Modifying Data PHP (cont.) 4D Methodology File and IO operations.
Faculty of Sciences and Social Sciences HOPE PHP & MySQL Stewart Blakeway FML 213
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
ADVM420- Class #4 Web Design with PHP and MySQL Adding and Listing from a MySQL Database.
Class 4 PHP MySQL Robert Mudge Reference:
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,
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
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.
Chapter 7 PHP Interacts with Ms. Access (Open DataBase Connectivity (ODBC))
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 MySQL and phpMyAdmin. 2 Navigate to and log on (username: pmadmin)
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Introduction to MySQL Lab no. 10 Advance Database Management System.
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.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
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.
Lecture 10 – MYSQL and PHP (Part 2)
PHP+MySQL Integration. Connecting to databases One of the most common tasks when working with dynamic webpages is connecting to a database which holds.
CHAPTER 9 PHP AND MYSQL. A POSSIBLE SITE CONFIGURATION Application Folder index.php includes (folder)header.phpfooter.phpstyle.cssmodel (folder)mysqli_connect.php.
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.
Retrieving data from MySQL using PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
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.
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.
PHP Programming. Topics Database Handling (MySQL, MSSQL, ODBC)
NMED 3850 A Advanced Online Design January 14, 2010 V. Mahadevan.
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.
MySQL MySQL and PHP – interacting with a database.
PHP with MYSQL Please use speaker notes for additional information!
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()
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
Lab 3.21 MySQL Database Lab Developing the Tools May 5 th, 2004 Montréal, Québec Dominik Gehl Hôpital Ste-Justine, Montréal.
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
Tried my best to simplify it for you!
Introduction to Dynamic Web Programming
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Web Design and Development
Introduction to Web programming
Advanced Internet Development Dynamic Web pages with php and MySQL
MySQL tutorial.
PHP: Database Basic Selection FdSc Module 109
PHP: Combo box FdSc Module 109 Server side scripting and
PHP: Database connection
Web Programming– UFCFB Lecture
Introduction to Web programming
Presentation transcript:

Class 3 MySQL Robert Mudge Reference:

MySQL Configuration/Installation  Installation from scratch  my.ini file  Passwords (old and new)  Command line operation

MySQL Tools  Review of Tools MySQL Administrator MySQL Query Browser MySQL PhpMyAdmin dbDesigner4

MySQL Create database  Best way – MySQL Administrator Create user Assign permission  Control Panel – Creation Example Create user Create database Assign user to database Watch username prefix

Create table of users  Create a table using phpMyAdmin for users (suggest lower case for variables and UPPER case for SQL) username password realname date  Add users to table using phpMyAdmin

Query – Select Statement  Reference – W3Schools  Using MySQL Query browser SELECT * FROM users; SELECT * FROM users WHERE username=‘smith’;

PHP MySQL Access - connect // function connect_to_database() { // $host = get_server(); $host = 'localhost'; $dbusername = 'bragn_admin'; $dbpassword = 'bragn_admin'; $database = 'bragnbracelets'; // setup the connection to the $db = mysql_connect($host, $dbusername, $dbpassword); if (!$db) { echo ' Error : Could not connect to database '; echo "Host : $host "; echo ' '; echo ' Please try again or contact the system administrator '; echo ' '; logger(mysql_error()); exit; $conn = mysql_select_db($database); if (!$conn) { logger(mysql_error()); exit; } return $db; }

PHP MySQL Access - connect function get_table_row($table, $key, $constraint) { $row = 0; // connect to db $db = connect_to_database(); $query = "select * from $table where $key = '$constraint'"; $result = mysql_query($query, $db); if ($result) { if (mysql_num_rows($result) > 1) { echo ' Warning : Query returns a non-unique result in enrollment. '; echo ' '; echo "Table : $table "; echo "Key : $key "; echo "Constraint: $constraint "; echo ' '; echo 'Showing the first result found '; echo 'Please examine the table data '; } $row = mysql_fetch_array($result); } else { echo " Error: No row found in $table for $key = $constraint "; } return $row; }

Homework 3  Create a role based database design. Create the database, populate with the given data and write PHP to access the database and perform the following queries.  Show all user names with the role of administrator.  Show what roles Susan Johnson has.  Show all the users, all their data  Show all the roles in ascending order of their level.  Turn in printed PHP source code and screen captures from your running program.

Users and Roles User Table - userid int(10) pkey - username char(20) - password char(20) Role Table - userid int(10) fkey - roleid int(10) fkey RoleTypes Table - roleid int(10) pkey - name char(20) - level int(10)

User Data  User Table Record 1  userid = ‘1000’  username = ‘jsmith’  password = ‘jsmith’  realname = ‘John Smith’ Record 2  userid = ‘1001’  username = ‘tjones’  password = ‘tjones’  realname = ‘Tom Jones’ Record 3  userid = ‘1002’  username = ‘sjohnson’  password = ‘sjohnsom’  realname = ‘Susan Johnson’

Role Types Data  RoleTypes Table Record 1  roleid = ‘100’  name = ‘guest’  level = 1 Record 2  roleid = ‘200’  name = ‘user’  level = 10 Record 3  roleid = ‘300’  name = ‘manager’  level = 100 Record 4  roleid = ‘400’  name = ‘administrator’  level = 1000

Role Data  RoleTypes Table Record 1  Userid = ‘1002’  roleid = ‘300’ Record 2  Userid = ‘1002’  roleid = ‘400’ Record 3  Userid = ‘1000’  roleid = ‘100’ Record 4  Userid = ‘1001’  roleid = ‘300’ Record 5  Userid = ‘1001’  roleid = ‘200’ Record 6  Userid = ‘1002’  roleid = ‘200’