Database basics

494 views
375 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
494
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Database basics

  1. 1. CGS 2835 Interdisciplinary Web Development Web Database Useful Web Apps +
  2. 2. CGS 2835 Interdisciplinary Web Development The Value of Databases • Databases and Database Management Systems (DBMS) transform large quantities of data into specific and valuable information for accomplishing some goal.
  3. 3. CGS 2835 Interdisciplinary Web Development AMP •Apache – open source Web server •MySQL – open source database •PHP – programming language that works in HTML to provide interactivity with MySQL
  4. 4. CGS 2835 Interdisciplinary Web Development Database Server Web ServerHTML REQUEST w/DATAHTML REQUEST w/DATA SQL CommandSQL Command PHP
  5. 5. CGS 2835 Interdisciplinary Web Development Database Server Web Server PHP data PHP-created HTML
  6. 6. CGS 2835 Interdisciplinary Web Development MySQL Database Server PHPdata PHP-created HTML SQLSQL Our Focus
  7. 7. CGS 2835 Interdisciplinary Web Development Databases
  8. 8. CGS 2835 Interdisciplinary Web Development File or Table Database • A collection of data organized to meet user’s needs. Records (Entities) Field (Attribute)
  9. 9. CGS 2835 Interdisciplinary Web Development Database Fields • Fields are set to hold specific types of data.
  10. 10. CGS 2835 Interdisciplinary Web Development Database A Database is a collection of files/tables
  11. 11. CGS 2835 Interdisciplinary Web Development Database Heirarchy Table
  12. 12. CGS 2835 Interdisciplinary Web Development Keys and Primary Key • Key: A field in a record that is used to identify the record • Primary key: A field that uniquely identifies a record – A primary key field prevents duplicate records from occurring in a table.
  13. 13. CGS 2835 Interdisciplinary Web Development Primary Keys • User identification number • Sometimes email addresses are used as a unique login, assuming two people cannot have the same email • A number is faster to look up, so a unique number is often still generated
  14. 14. CGS 2835 Interdisciplinary Web Development Primary Key
  15. 15. CGS 2835 Interdisciplinary Web Development The Relational Model • In a relational database, tables are linked (related) through common fields. • This can remove redundant data, and organize information
  16. 16. CGS 2835 Interdisciplinary Web Development “Flat” database userID First Name Last Name Email, …, … Message 1 Geo Miller …, … , … Hello! 2 Ken Baldauf …, … , … Greetings, how are you? 1 Geo Miller …, … , … Doing well 2 Ken Baldauf ……, … , … Great! The Relational Model
  17. 17. CGS 2835 Interdisciplinary Web Development “Relational” databaseuserID First Name Last Name Email, …, … 1 Geo Miller …, … , … 2 Ken Baldauf …, … , … The Relational Model userID Message 1 Hello! 2 Greetings, how are you? 1 Doing well 2 Great!
  18. 18. CGS 2835 Interdisciplinary Web Development Relation Types • One-to-many – Makes use of primary key – Example: one person makes many posts • One-to-one – A piece of data only relating to one record • Many-to-many – An item can have many sellers and sellers can sell that item many times
  19. 19. CGS 2835 Interdisciplinary Web Development MySQL An open-source, relational database
  20. 20. CGS 2835 Interdisciplinary Web Development MySQL - Installing • Some servers require an administrator to install • On your own machine, there are installation packages for AMP • On Codio: – parts install mysql – parts start mysql • On many linux distributions: – apt-get install mysql-server – service mysql start
  21. 21. CGS 2835 Interdisciplinary Web Development MySQL – Creating a Database Creating a database in MySQL is traditionally done with a terminal that has administrator access to the MySQL server. CREATE DATABASE IF NOT EXISTS “databasename” A MySQL user must be created and given access to use the new database CREATE USER IF NOT EXISTS “username” SET PASSWORD FOR “username”=PASSWORD(“password”) GRANT ALL PRIVILEGES ON “databasename” TO “username” IDENTIFIED BY “password”
  22. 22. CGS 2835 Interdisciplinary Web Development phpMyAdmin is a popular application for managing mySQL databases. Here you can click a database name to access its properties and tools. Note that whenever prompted for charset or collation select UTF-8 Unicode (utf8).
  23. 23. CGS 2835 Interdisciplinary Web Development Access MySQL Database We will use phpMyAdmin to: •Create tables in databases •Create fields in the tables •Manage the database •Examine table data We will use PHP to: • Enter records into tables from HTML forms • Read records from tables and output to HTML pages
  24. 24. CGS 2835 Interdisciplinary Web Development When I click my database link in phpMyAdmin, I am prompted to create a table.
  25. 25. CGS 2835 Interdisciplinary Web Development Then I create fields for my table.
  26. 26. CGS 2835 Interdisciplinary Web Development I can then use the Insert tab to enter records into the table.
  27. 27. CGS 2835 Interdisciplinary Web Development
  28. 28. CGS 2835 Interdisciplinary Web Development The browse buttons allows you to view the contents of the table.
  29. 29. CGS 2835 Interdisciplinary Web Development
  30. 30. CGS 2835 Interdisciplinary Web Development You can also run SQL queries on your data from within phpMyAdmin.
  31. 31. CGS 2835 Interdisciplinary Web Development MySQL & phpMyAdmin • phpMyAdmin is a useful tool for manipulating mySQL databases; however, in order to work with Web-generated data, the mySQL database must be accessed from the HTML code using PHP. MySQL Database Server SQLSQLSQLSQL PHP
  32. 32. CGS 2835 Interdisciplinary Web Development MySQL & phpMyAdmin • Either method of interacting with the database requires knowledge of SQL MySQL Database Server SQLSQLSQLSQL PHP

×