Presentation is loading. Please wait.

Presentation is loading. Please wait.

Class 3Intro to Databases Class 4 Simple Example of a Database We’re going to build a simple example of a database, which will allow us to register users.

Similar presentations


Presentation on theme: "Class 3Intro to Databases Class 4 Simple Example of a Database We’re going to build a simple example of a database, which will allow us to register users."— Presentation transcript:

1 Class 3Intro to Databases Class 4 Simple Example of a Database We’re going to build a simple example of a database, which will allow us to register users and allow them to log in to do this, we’re going to 1- design a database that fits our needs 2- create templates that allow us to view and enter information 3- enter records into the database 4- write scripts that allow us to a- view the information b- enter the information

2 Class 3Intro to Databases Class 4 Project To create our database and the tables for this project, we need to understand what our project will be. Project Description Create a system that allows 1- new users to register 2- existing users to login 3- existing users to change their passwords 4- existing users to view all users

3 Class 3Intro to Databases Class 4 DESIGNING THE SITE (from a programming point of view)

4 Class 3Intro to Databases Class 4 Site Map A Site Map is an overall look at the pages & links within a site from a users point of view. It indicates how users can get from point A to point B.

5 Class 3Intro to Databases Class 4 What the site will look like image here

6 Class 3Intro to Databases Class 4 Site Flow The Site Flow is an overall look at the pages & links within a site from a programming point of view. It indicates how the program flows from point A to point B.

7 Class 3Intro to Databases Class 4

8 Class 3Intro to Databases Class 4 Site IA The Information Architecture describes 1- the elements that make up a page and 2- how they function

9 Class 3Intro to Databases Class 4 Site IA

10 Class 3Intro to Databases Class 4 Site IA

11 Class 3Intro to Databases Class 4 Site IA REGISTER has 2 states Form Confirm

12 Class 3Intro to Databases Class 4 Site IA

13 Class 3Intro to Databases Class 4 Site IA

14 Class 3Intro to Databases Class 4 Site IA LOGIN has 2 states Form Confirm

15 Class 3Intro to Databases Class 4 Site IA

16 Class 3Intro to Databases Class 4 Site IA

17 Class 3Intro to Databases Class 4 Site IA CHANGE PASSWORD has 2 states Form Confirm

18 Class 3Intro to Databases Class 4 Site IA

19 Class 3Intro to Databases Class 4 Site IA

20 Class 3Intro to Databases Class 4 Site IA VIEW USERS has only one state

21 Class 3Intro to Databases Class 4 Site IA

22 Class 3Intro to Databases Class 4 Directory Structure The directory structure outlines where files will be stored.

23 Class 3Intro to Databases Class 4 CREATING THE TEMPLATE

24 Class 3Intro to Databases Class 4 Creating the template

25 Class 3Intro to Databases Class 4 Creating the template Content.... "); //FOOTER include ('./templates/footer.php'); // Include the HTML footer. ?>

26 Class 3Intro to Databases Class 4 Creating the template PHP has 4 functions for using external files include() include_once() require() require_once To use them, your script needs a line like include (‘filename.php'); What’s the difference? If an include file is not found it will display an error, but other scripts will run if a require file is not found, it will display and error and the other scripts will NOT run include_once() and require_once will be called only once, no matter how many times your scripts refer to them

27 Class 3Intro to Databases Class 4 Creating the header file Welcome to my site! Home Register

28 Class 3Intro to Databases Class 4 Creating the footer file Home Register © 2003 Larry E. Ullman and DMC Insights, Inc.

29 Class 3Intro to Databases Class 4 WRITING THE SCRIPTS

30 Class 3Intro to Databases Class 4 Writing the scripts Preciously we used 2 scripts to handle our HTML forms. One to display the form One to process it Using some of the logic we learned last week, we’re going to combine both of these processes into one form.

31 Class 3Intro to Databases Class 4 Writing the scripts

32 Class 3Intro to Databases Class 4 Writing the scripts Display the footer User defined functions Display the header Check if form has been submitted If YES, do error checking If NO, display form Does information pass error checking? If YES, register user and print confirm message If NO, display error message and form

33 Class 3Intro to Databases Class 4 Writing the scripts 0) { } else { $error_message.= " You forgot to enter your username! "; } // Do I PASS ERROR CHECKING? if ($error_message=="" ) { // If everything's okay. // Register the user. // DATABSE FUNCTIONALITY WILL GO HERE //print verification/confirm message } else { // There's an error. //print error message print_registration_form(); } } else { // Display the form. print_registration_form(); } // End of the main SUBMIT conditional. include ('./templates/footer.php'); // Include the HTML footer. function print_registration_form(){ … } ?> Display the footer User defined functions Display the header Check if form has been submitted If YES, do error checking If NO, display form Does information pass error checking? If YES, register user and print confirm message If NO, display error message and form

34 Class 3Intro to Databases Class 4 DESIGNING THE DATABASE & TABLE

35 Class 3Intro to Databases Class 4 What the table will look like This table is relatively simple. 1- We have one main “type” of thing to worry about –users, so we’re going to create one table 2- From the IA we know there are 7 things we need to have for each user First Name Last Name E-mail User Name Password User ID (gives us a way to uniquely id each user) Registration Date

36 Class 3Intro to Databases Class 4 What the table will look like To fully construct our table we need to define the data type required by each column. My SQL has a number of data types, but they break down into a few basic categories BOOLEAN NUMBERS Integer, Float, Decimal etc DATE Datetime, Timestamp, etc TEXT Char, Varchar, Text, Blob

37 Class 3Intro to Databases Class 4 Data Types have to be correct – otherwise you will be trying to put a square peg in a round hole. Once in a while it will work, but often it will be impossible.

38 Class 3Intro to Databases Class 4 These are further broken down, usually by the how much information each variable can store BOOLEAN - no sub categories NUMBERS TINYINT - A very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255 SMALLINT - A small integer. The signed range is -32768 to 32767. The unsigned range is 0 to 65535. MEDIUMINT - A medium-size integer. The signed range is -8388608 to 8388607. The unsigned range is 0 to 16777215. INT- A normal-size integer. The signed range is -2147483648 to 2147483647. The unsigned range is 0 to 4294967295. BIGINT - A large integer. The signed range is -9223372036854775808 to 9223372036854775807. The unsigned range is 0 to 18446744073709551615.

39 Class 3Intro to Databases Class 4 What the table will look like NUMBERS (cont’d) FLOAT- A small (single-precision) floating-point number. Allowable values are -3.402823466E+38 to -1.175494351E-38, 0, and 1.175494351E-38 to 3.402823466E+38. DOUBLE - A normal-size (double-precision) floating-point number. Allowable values are -1.7976931348623157E+308 to - 2.2250738585072014E-308, 0, and 2.2250738585072014E-308 to 1.7976931348623157E+308. DECIMAL- An unpacked floating-point number. Behaves like a CHAR column: ``unpacked'' means the number is stored as a string, using one character for each digit of the value.

40 Class 3Intro to Databases Class 4 What the table will look like TEXT VARCHAR - A variable-length string. The range is 0 to 255 characters (1 to 255 prior to MySQL Version 4.0.2). TINYBLOB TINYTEXT - A BLOB or TEXT column with a maximum length of 255 characters. BLOB TEXT A BLOB or TEXT column with a maximum length of 65535 characters. MEDIUMBLOB MEDIUMTEXT A BLOB or TEXT column with a maximum length of 16777215 (2^24 - 1) characters. LONGBLOB LONGTEXT A BLOB or TEXT column with a maximum length of 4294967295 or 4G (2^32 - 1) characters.

41 Class 3Intro to Databases Class 4 What Data Type to use for each column? This is always a tricky question. For our example let’s go back to the project IA and some common sense. First Name - Since the IA says that this has a max number of 30 characters and it’s a text string, I’m going to make it a VARCHAR with a max of 30 characters Last Name- Since the IA says that this has a max number of 30 characters and it’s a text string, I’m going to make it a VARCHAR with a max of 30 characters E-mail Name- Since the IA says that this has a max number of 255 characters and it’s a text string, I’m going to make it a VARCHAR with a max of 255 characters User Name- Since the IA says that this has a max number of 10 characters and it’s a text string, I’m going to make it a VARCHAR with a max of 10 characters

42 Class 3Intro to Databases Class 4 What Data Type to use for each column? Password - Since the IA says that this has a max number of 10 characters and it’s a text string, I’m going to make it a VARCHAR with a max of 10 characters User ID – This is going to be a unique number for each user. I can’t imagine I’m going to have more than 16777215 users, so I’m going to make it a MEDIUM INT unsigned Registration Date– I want to get both the date and time a user registered, so I’m going to make it a DATETIME type

43 Class 3Intro to Databases Class 4 What Data Type to use for each column? This is the DATASPEC to design our table Also PRIMARY KEY

44 Class 3Intro to Databases Class 4 CREATING THE TABLE

45 Class 3Intro to Databases Class 4 Creating a Database We’re going to use phpMyAdmin to create our database.

46 Class 3Intro to Databases Class 4 Installing phpMyAdmin 1- download phpMyAdmin http://www.phpmyadmin.net/home_page/ 2- unzip the file 3- rename the folder phpMyAdmin 4- changes to config.inc.php http://www.phpmyadmin.net/home_page/

47 Class 3Intro to Databases Class 4 Installing phpMyAdmin config.inc.php The directory for phpMyAdmin on your site For example http://denning.net/phpMyAdmin The user name & password from Kunal

48 Class 3Intro to Databases Class 4 Installing phpMyAdmin 5- upload the folder phpMyAdmin 6- go to the full url you used for example http://denning.net/phpMyAdmin

49 Class 3Intro to Databases Class 4 Using phpMyAdmin creating a database

50 Class 3Intro to Databases Class 4 Using phpMyAdmin creating a table Name – is arbitrary, but it should make some sense Number of fields – we know this from our dataspec –

51 Class 3Intro to Databases Class 4 Using phpMyAdmin naming columns and assigning datatypes Field Name – should come from our dataspec Type – we know this from our dataspec Length/Values – we know this from our dataspec Extra– we know this from our dataspec Key – we know this from our dataspec –

52 Class 3Intro to Databases Class 4 Using phpMyAdmin naming columns and assigning datatypes –

53 Class 3Intro to Databases Class 4 Using phpMyAdmin –

54 Class 3Intro to Databases Class 4 Using phpMyAdmin entering records – Click this to enter a record Leave this blank – we’re using Auto Increment

55 Class 3Intro to Databases Class 4 Using phpMyAdmin viewing records – Click this to view records


Download ppt "Class 3Intro to Databases Class 4 Simple Example of a Database We’re going to build a simple example of a database, which will allow us to register users."

Similar presentations


Ads by Google